Add a thread-local cache disable pool test (depends on database-connector#26)#535
Closed
marknefedov wants to merge 1 commit into
Closed
Add a thread-local cache disable pool test (depends on database-connector#26)#535marknefedov wants to merge 1 commit into
marknefedov wants to merge 1 commit into
Conversation
TryAcquireFromThreadLocal stopped consulting the cache as soon as tl_cache_enabled went false, but a connection already parked in this thread's cache was left there. It keeps counting towards total_connections, so it occupies a pool slot that nothing can hand out again: Connection pool timeout: all 1 connections in use, waited 100ms Hand the parked connection back to the global pool instead. Clear() already routes through ReturnFromThreadLocalCache, which re-checks expiry and the max_connections bound, so this reuses the existing return path. This only recovers the slot of a thread that acquires again after the cache was disabled. Dormant worker threads still hold their connection until their ThreadLocalConnectionCache is destroyed - draining those would need a generation counter or a registry of live caches.
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.
What this is
The SQL-level regression test for the thread-local connection cache leak. The fix itself is in the
database-connectorsubmodule (duckdb/database-connector#26); only the test belongs in this repo.The bug
TryAcquireFromThreadLocalstops consulting the cache as soon astl_cache_enabledgoes false, but a connection already parked in that thread's cache is left there. It still counts towardstotal_connectionswhile being unreachable, so it permanently occupies a pool slot:Reachable from this repo through
postgres_configure_pool(enable_thread_local_cache := false)on a pool that had the cache enabled and in use.The test
test/sql/storage/attach_connection_pool_tl_cache_disable.testwalks enable → park → shrink → disable → query.Two things worth flagging for review:
threads=1. The connection has to be parked and re-acquired on the same thread for the drain to fire, since the fix only recovers the calling thread's slot.max_connections=1. If a single connection were not enough for this query, the later assertion could not distinguish a stranded connection from a query that simply needs two — the control makes that failure mode explicit rather than silent.The pool also has a
test/test_pool.cppunit test in the connector PR, which is the more direct regression. Note thatdatabase-connector/testis not wired into this repo's CI, so that one only runs in the connector repo.To land
database-connectorsubmodule pointer on this branch