Files
bun.sh/test/js/sql/sql-fixture-unref.ts
Claude Bot 12bc09718c fix(sql): allow process to exit when PostgreSQL connection is idle
Previously, idle PostgreSQL connections would keep the Bun process alive
indefinitely after queries completed. This happened because `updateRef()`
always kept the poll reference when `pending_activity_count > 0`, which
includes any non-disconnected connection status.

This fix modifies `updateRef()` to unref the poll when the connection is
idle (connected with no pending queries and no data to write), matching
Node.js behavior where idle database connections allow the process to exit.

Fixes #3548

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 01:08:55 +00:00

24 lines
834 B
TypeScript
Generated

// This test verifies that idle PostgreSQL connections allow the process to exit.
// Fixes #3548: Database clients that maintain persistent connections should not
// prevent the Bun process from exiting after queries complete.
//
// This test passes by:
// 1. Printing "query_done"
// 2. Exiting with code 0 within a reasonable timeout
//
// If the bug is present, the process will hang indefinitely after the query completes.
import { sql } from "bun";
async function main() {
// Execute a query
const result = await sql`select 1 as x`;
console.log("query_done");
// The connection is now idle. The process should exit naturally
// without needing to explicitly close the connection.
// Note: We intentionally do NOT call sql.close() here to test that
// idle connections don't keep the process alive.
}
main();