Repository navigation
Conversation
close() started closing each connection in the background and completed onClose at once, so onClose callbacks ran while connections were still closing. Consumers had no way to wait until the connections were really closed (e.g. a child process still holding an SQLite file lock). close() stays non-blocking and isClosed() still returns true at once, but onClose now completes once every connection's close() has settled, errors included. A connection being opened during close() is closed by close() and awaited too, and pop() no longer starts a connection attempt after the pool is closed. Co-Authored-By: Claude <noreply@anthropic.com>
…guard Gate connect() and close() with DeferredFutures instead of delays, add a test that no connection is opened once the pool is closed while a second query waits on the first connection attempt, and document that onClose waits for every connection's close() to settle. Co-Authored-By: Claude <noreply@anthropic.com>
clfer
force-pushed
the
fix-pool-close-await-connections
branch
from
November 23, 2026 00:18
1b65721 to
140ccd8
Compare
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 #9
SqlCommonConnectionPool::close()completedonCloseright after starting each connection'sclose()in the background, soonClosecallbacks ran while connections were still closing. With fabpot/amphp-sqlite3, the child process could still hold the database file, and reopening it failed on Windows with "database is locked" (repro: clfer/amp-sqlite3-fork@f2f57ea).Change
close()stays non-blocking, andisClosed()still returnstrueat once (new$closedflag).onClosecompletes once every connection'sclose()has settled, errors included (Future\awaitAll()). With no connections, it completes at once, as before.close()is called is closed byclose()and awaited too.pop()no longer starts a connection attempt once the pool is closed. Before, apop()waiting on another attempt could still open a new connection afterclose(), only to close it right away, andonClosedid not wait for it.onClosecallbacks now run later than before: only once every connection'sclose()(and any pendingconnect()) has settled, so a driver whoseclose()can hang delaysonCloseindefinitely. No timeout is added, since it would bring the race back.SqlConnectionTransactionalready completesonClosethis way, after its asynchronous rollback.Tests
New tests in
SqlCommonConnectionPoolTestgateconnect()andclose()withDeferredFutures (no timing):onClosewaits for connections to close, still runs whenclose()throws, waits for a connection opened duringclose(), no connection is opened afterclose(), andclose()stays idempotent. Three of them fail on2.xand all pass with this change. Psalm and php-cs-fixer report nothing new.