Merge pull request #36920 from kolyshkin/cancel-func

context.WithTimeout: do call the cancel func
This commit is contained in:
Sebastiaan van Stijn 2018-04-23 20:14:25 +02:00 committed by GitHub
commit 20b524bf2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -504,7 +504,8 @@ func validateAddr(addr string) (string, error) {
}
func initClusterSpec(node *swarmnode.Node, spec types.Spec) error {
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
for conn := range node.ListenControlSocket(ctx) {
if ctx.Err() != nil {
return ctx.Err()

View File

@ -80,7 +80,8 @@ func (p *perpetualReader) Read(buf []byte) (n int, err error) {
}
func TestCancelReadCloser(t *testing.T) {
ctx, _ := context.WithTimeout(context.Background(), 100*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
cancelReadCloser := NewCancelReadCloser(ctx, ioutil.NopCloser(&perpetualReader{}))
for {
var buf [128]byte