Fix connection hang in database_is_empty() for SerenDB/Neon targets#24
Merged
Conversation
Reuse the existing target_client connection instead of creating a new connection when checking if a database is empty. This prevents connection pool exhaustion on serverless PostgreSQL providers (SerenDB, Neon) that have strict concurrent connection limits. The previous implementation would create a second connection while the first was still open, causing indefinite hangs when the connection pool was exhausted. Since tokio_postgres::connect has no built-in timeout, the operation would hang forever. Fixes #23
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.
Summary
initagainst SerenDB/Neon targets where the database already existstarget_clientconnection instead of creating a new connection indatabase_is_empty()Problem
When
database_is_empty()was called, it created a second database connection while the firsttarget_clientconnection was still active. SerenDB/Neon has strict concurrent connection limits, and sincetokio_postgres::connecthas no built-in timeout, the operation would hang indefinitely waiting for a connection slot.Reproduced on jobs:
438c3593-057c-45f3-9d23-6ddce6cea1bb314eacf8-5fcc-48d5-822a-3350f3b5a0e3Both hung for 6+ minutes at:
Solution
Changed
database_is_empty()to accept a&Clientreference instead of creating a new connection. The existingtarget_clientis already connected to the correct database and can be reused.Test plan
cargo buildpassescargo clippypassescargo testpasses (67 tests)Fixes #23