Skip to content

Fix connection hang in database_is_empty() for SerenDB/Neon targets#24

Merged
taariq merged 1 commit into
mainfrom
fix/database-is-empty-connection-hang
Dec 3, 2025
Merged

Fix connection hang in database_is_empty() for SerenDB/Neon targets#24
taariq merged 1 commit into
mainfrom
fix/database-is-empty-connection-hang

Conversation

@taariq
Copy link
Copy Markdown
Contributor

@taariq taariq commented Dec 3, 2025

Summary

  • Fixes indefinite hang when running init against SerenDB/Neon targets where the database already exists
  • Reuses the existing target_client connection instead of creating a new connection in database_is_empty()
  • Prevents connection pool exhaustion on serverless PostgreSQL providers

Problem

When database_is_empty() was called, it created a second database connection while the first target_client connection was still active. SerenDB/Neon has strict concurrent connection limits, and since tokio_postgres::connect has no built-in timeout, the operation would hang indefinitely waiting for a connection slot.

Reproduced on jobs:

  • 438c3593-057c-45f3-9d23-6ddce6cea1bb
  • 314eacf8-5fcc-48d5-822a-3350f3b5a0e3

Both hung for 6+ minutes at:

INFO: Database 'serendb' already exists on target
[HANG - no further output]

Solution

Changed database_is_empty() to accept a &Client reference instead of creating a new connection. The existing target_client is already connected to the correct database and can be reused.

Test plan

  • cargo build passes
  • cargo clippy passes
  • cargo test passes (67 tests)
  • Manual test with SerenDB target (requires deployment)

Fixes #23

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
@taariq taariq merged commit 7abe450 into main Dec 3, 2025
7 checks passed
@taariq taariq deleted the fix/database-is-empty-connection-hang branch December 3, 2025 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Init command hangs on database_is_empty() when database already exists on SerenDB/Neon

1 participant