From e5f3762192f6616d3081c258df692f0052517acd Mon Sep 17 00:00:00 2001 From: Hedayet Date: Thu, 30 Mar 2017 16:12:36 +1100 Subject: [PATCH] Exec the cancel returned by context.WithTimeout the cancel function returned by context.WithTimeout should be called, not discarded, to avoid a context leak. --- timeout.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/timeout.go b/timeout.go index 5c4fb6b..e424f9a 100644 --- a/timeout.go +++ b/timeout.go @@ -22,17 +22,20 @@ func (s *timeoutManager) Open() (err error) { return s.chain.Open() } func (s *timeoutManager) Close() (err error) { return s.chain.Close() } func (s *timeoutManager) Put(ctx context.Context, key string, val []byte) (err error) { - ctx, _ = context.WithTimeout(ctx, s.timeout) + ctx, cancel = context.WithTimeout(ctx, s.timeout) + defer cancel() return s.chain.Put(ctx, key, val) } func (s *timeoutManager) Get(ctx context.Context, key string) (data []byte, err error) { - ctx, _ = context.WithTimeout(ctx, s.timeout) + ctx, cancel = context.WithTimeout(ctx, s.timeout) + defer cancel() return s.chain.Get(ctx, key) } func (s *timeoutManager) Del(ctx context.Context, key string) (err error) { - ctx, _ = context.WithTimeout(ctx, s.timeout) + ctx, cancel = context.WithTimeout(ctx, s.timeout) + defer cancel() return s.chain.Del(ctx, key) }