From 211365a4a5ee4334a06536823cbc4103cb16fb04 Mon Sep 17 00:00:00 2001 From: Daniil Aksenov Date: Thu, 14 Nov 2024 21:22:40 +0300 Subject: [PATCH] fix pool item close --- CHANGELOG.md | 2 ++ internal/pool/pool.go | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef0bfbd4f..0c06cddab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Fixed connections pool leak on closing + ## v3.92.2 * Added `table/options.WithShardNodesInfo()` experimental option to get shard nodeId for describe table call diff --git a/internal/pool/pool.go b/internal/pool/pool.go index 88fa5724f..1df29f27c 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -296,15 +296,15 @@ func makeAsyncCloseItemFunc[PT ItemConstraint[T], T any]( p *Pool[PT, T], ) func(ctx context.Context, item PT) { return func(ctx context.Context, item PT) { - closeItemCtx, closeItemCancel := xcontext.WithDone(xcontext.ValueOnly(ctx), p.done) - defer closeItemCancel() - - if d := p.config.closeTimeout; d > 0 { - closeItemCtx, closeItemCancel = xcontext.WithTimeout(ctx, d) + go func() { + closeItemCtx, closeItemCancel := xcontext.WithDone(xcontext.ValueOnly(ctx), p.done) defer closeItemCancel() - } - go func() { + if d := p.config.closeTimeout; d > 0 { + closeItemCtx, closeItemCancel = xcontext.WithTimeout(ctx, d) + defer closeItemCancel() + } + _ = item.Close(closeItemCtx) }() }