소스 검색

client: fix goroutine leak in unreleased context

If headerTimeout is not zero then two context are created but only one is released.
cancelCtx in this case is never released which leads to goroutine leak inside it.
Andrei Korzhevskii 10 년 전
부모
커밋
cb9a3e04b1
1개의 변경된 파일과 4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      client/client.go

+ 4 - 1
client/client.go

@@ -378,9 +378,12 @@ func (c *simpleHTTPClient) Do(ctx context.Context, act httpAction) (*http.Respon
 		return nil, nil, err
 	}
 
-	hctx, hcancel := context.WithCancel(ctx)
+	var hctx context.Context
+	var hcancel context.CancelFunc
 	if c.headerTimeout > 0 {
 		hctx, hcancel = context.WithTimeout(ctx, c.headerTimeout)
+	} else {
+		hctx, hcancel = context.WithCancel(ctx)
 	}
 	defer hcancel()