Repository navigation
Conversation
Queue time in the shared DriverDialectExecutor no longer counts against socket_timeout, so a fast query waiting behind a saturated pool does not raise QueryTimeoutError. A call that actually runs too long still times out.
On queue-wait expiry, cancel the future and block the worker from starting the call after the caller gives up. If cancel loses the race, run abort/drain. Bound queue wait by max(timeout*2, timeout+5).
hippi345
marked this pull request as ready for review
October 17, 2026 17:26
This branch has not been deployed
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.
Description
Fixes #1278.
socket_timeoutis enforced by submitting the underlying driver call to a sharedThreadPoolExecutor(DriverDialectExecutorfromservices_container.get_thread_pool) and callingfuture.result(timeout=socket_timeout). That clock used to start atsubmit(), so time spent queued behind other in-flight calls counted as query time. When the process-wide pool is saturated (default sizemin(32, cpu_count + 4)), a fast query could raiseQueryTimeoutErrorwithout ever being slow on the database.This PR starts the timeout clock when a worker actually begins the call. Queue delay is not charged against
socket_timeout.Queue-bound expiry (correctness): if the call is still queued when the queue-wait bound expires, the future is
cancel()led and a lock/abandonedflag prevents the worker from startingfuncafter the caller has given up. Ifcancel()returnsFalse(the worker started in that window), the call is treated as started and the existing abort/drain path runs. That closes the hole where the caller already had a timeout and the submitted work later ran on the same connection.Queue-wait bound:
max(timeout * 2, timeout + 5)seconds, notmax(timeout * 10, 60). A 5ssocket_timeoutcan wait at most 10s for a worker (instead of 60s), which is enough extra time to get scheduled under contention without amplifying pile-ups during an outage. A 0.2s timeout still has 5.2s to get a worker. No new connection property: the bound is derived fromsocket_timeoutso it stays in the existing timeout API.No pool-size property.
get_thread_poolis unchanged.Maintainer options (this PR is open to switching approach):
socket_timeoutmatches actual driver/socket time. Trade-offs: a saturated pool can delay a caller until a worker is free (or until the queue-wait bound); the default pool can still be a hidden concurrency ceiling smaller than the application's connection pool.DriverDialectExecutorpool size. Add a wrapper property (e.g.driver_dialect_executor_max_workers) plus docs. Lets operators size the pool to expected DB concurrency. Trade-off: does not by itself stop queue time from counting as query time if the pool is still too small.Happy to switch to (b) or (c) if that is the preferred design.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
This change was prepared with AI assistance and reviewed by the author.