fix: Fix connection slot leak when context is cancelled during acquire#1759
Merged
kavirajk merged 10 commits intoClickHouse:mainfrom Mar 4, 2026
Merged
fix: Fix connection slot leak when context is cancelled during acquire#1759kavirajk merged 10 commits intoClickHouse:mainfrom
kavirajk merged 10 commits intoClickHouse:mainfrom
Conversation
kavirajk
reviewed
Feb 3, 2026
tests/context_cancel_test.go
Outdated
| // eventually exhaust the connection pool. | ||
| func TestContextCancellationNoConnectionSlotLeak(t *testing.T) { | ||
| TestProtocols(t, func(t *testing.T, protocol clickhouse.Protocol) { | ||
| SkipOnHTTP(t, protocol, "context cancel slot leak test") |
Contributor
There was a problem hiding this comment.
I wonder, why do we skip on this on HTTP? both TCP and HTTP uses pooling via these acquire() api.
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
in dial_http, we modify the passed in options in-plce. Which restricts (and cause data race) when end up using multiple go-routines This PR uses just the local copy of the options's compression and scheme during dial_http Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
kavirajk
approved these changes
Mar 4, 2026
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a connection pool leak that happens when a query context is cancelled while acquiring a connection. When
acquire()gets a connection slot from thech.openchannel but thench.idle.Get(ctx)returns a context cancellation error, we were returning immediately without releasing that slot. After enough cancelled queries, the pool would be exhausted even though connections were available.This fix makes sure the slot gets released. It also adds a test that reproduces the previous issue and shows that is now fixed.