Skip to content

Commit 71091c4

Browse files
committed
cleanup for context cancellation in etcd
1 parent af87f77 commit 71091c4

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

.cirrus.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
container:
2-
image: golang:1.13
1+
task:
2+
env:
3+
GOPROXY: https://proxy.golang.org
4+
matrix:
5+
VERSION: 1.13
6+
VERSION: 1.14
7+
VERSION: 1.15
38

4-
env:
5-
GOPROXY: https://proxy.golang.org
9+
container:
10+
image: golang:$VERSION
11+
12+
name: test-$VERSION
613

7-
test_task:
814
test_script:
915
- apt-get update
1016
- apt-get install -y asciidoc docbook-utils docbook-xml libxml2-utils xsltproc
@@ -17,8 +23,8 @@ test_task:
1723
- make get-deps check
1824

1925
docker_builder:
20-
depends_on:
21-
- test
26+
name: docker
27+
2228
build_script:
2329
- GOPATH=/tmp/go
2430
- PATH="$PATH:$GOPATH/bin"

pkg/utils/etcd.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ func (c *Client) SetErrorBanner(errorBanner string, expire time.Time) error {
386386
key := "/sshproxy/error_banner/value"
387387
keyExpire := "/sshproxy/error_banner/expire"
388388
ctx, cancel := context.WithTimeout(context.Background(), c.requestTimeout)
389+
defer cancel()
389390
currentTime := time.Now()
390391
diff := expire.Sub(currentTime)
391392
seconds := int64(diff.Seconds())
@@ -396,7 +397,6 @@ func (c *Client) SetErrorBanner(errorBanner string, expire time.Time) error {
396397
}
397398
_, err = c.cli.Put(ctx, key, errorBanner, clientv3.WithLease(resp.ID))
398399
_, err2 := c.cli.Put(ctx, keyExpire, expire.Format("2006-01-02 15:04:05"), clientv3.WithLease(resp.ID))
399-
cancel()
400400
if err != nil {
401401
return err
402402
}
@@ -406,7 +406,6 @@ func (c *Client) SetErrorBanner(errorBanner string, expire time.Time) error {
406406
} else {
407407
_, err := c.cli.Put(ctx, key, errorBanner)
408408
_, err2 := c.cli.Delete(ctx, keyExpire)
409-
cancel()
410409
if err != nil {
411410
return err
412411
}

0 commit comments

Comments
 (0)