Repository navigation
Fail fast on refused database connections - #394
Merged
Merged
Conversation
SQLx's pool retries ConnectionRefused with exponential backoff for the full acquire_timeout (30s by default), then discards the I/O error and returns PoolTimedOut. When a non-SQLite pool is still connecting after 3 seconds, probe the host directly and abort immediately on ConnectionRefused with the real I/O error and target host/port (or socket) in the message. Amp-Thread-ID: https://ampcode.com/threads/T-4b34fcd3-0d8f-4878-a303-28fa30e6d865 Co-authored-by: Taylor Otwell <taylor@laravel.com>
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.
Problem
When a configured PostgreSQL or MySQL server isn't running (for example, running
laravel migratein a fresh app before setting up Postgres),SQLx's pool catchesio::ErrorKind::ConnectionRefusedand retries it with exponential backoff for the fullacquire_timeout(30 seconds by default), then discards the I/O error and returnsPoolTimedOut("pool timed out while waiting for an open connection").Fix
crates/database/src/db/pools.rs, when a non-SQLite pool is still connecting after 3 seconds, probe the host directly withoptions.connect().ConnectionRefused, abortpool.acquire()immediately and return that I/O error instead of waiting 30 seconds forPoolTimedOut.pool.acquire()finish.57P03/53300) still letSQLxkeep retrying up toacquire_timeout.host:portor Unix socket):tests/migrations.rsverifyingmigratefails fast against an unbound local port with the default 30sacquire_timeout.