Skip to content

fix: Pool connect-failure handling and empty closed-Statement error message - #505

Open
younjungpark wants to merge 3 commits into
IBM:mainfrom
younjungpark:fix/pool-connect-failure-and-statement-error
Open

younjungpark wants to merge 3 commits into
IBM:mainfrom
younjungpark:fix/pool-connect-failure-and-statement-error

Conversation

@younjungpark

@younjungpark younjungpark commented Nov 20, 2026 •

Copy link
Copy Markdown

This PR fixes three small bugs, one per commit. Each commit includes a regression test.

1. Pool.query() with a callback crashes the process when the pool cannot connect

With a callback, a connection error was thrown inside the connect() callback. Nothing could catch it, so the process exited with an uncaught exception instead of the error reaching the user's callback. The Promise path already rejects correctly. The callback path now passes the error to the user's callback (on process.nextTick, like the success path).

2. Pool waits forever after a failed connection attempt

connectionsBeingCreatedCount was incremented for each attempt but only decremented on success. After one failed attempt, the next query()/connect() waited for a connection that was never going to be created and never resolved or called back. The counter is now decremented on the error path too, before connectionError is emitted, so work retried from that handler sees the correct count.

3. Errors from a closed Statement have an empty message

STATEMENT_CLOSED_ERROR was an instance field, but the code reads Statement.STATEMENT_CLOSED_ERROR, which was undefined. prepare(), bind(), execute(), etc. on a closed statement therefore threw/returned new Error(undefined). It is now a static field, so the message is Statement has already been closed!. (The instance property statement.STATEMENT_CLOSED_ERROR is gone; it was not part of the typings or docs.)

Tests

  • test/pool/query.test.js: connection-failure tests use DRIVER=NoSuchOdbcDriver, so they do not depend on a DBMS. Without the fixes, test 1 fails with an uncaught error and the two tests for fix 2 time out.
  • test/statement/close.test.js: checks the error message after close() (callback and Promise). Without the fix, the message is ''.
  • I ran the new tests and the full Pool and Statement suites against Altibase (through its ODBC driver), and they all pass. The full suite has some other failures on Altibase, which is not one of the DBMSs the test suite targets. Those failures are the same with and without this change.

Geoffrey Park added 3 commits November 20, 2026 14:47
When Pool.query() was called with a callback and the pool could not open
a connection, the connection error was thrown inside the connect callback.
Nothing could catch it, so the process crashed with an uncaught exception
instead of the error reaching the user's callback.

Pass the connection error to the user's callback instead, matching the
Promise path, which already rejects with it.

Signed-off-by: Geoffrey Park <handsomeboy72@gmail.com>
When the pool failed to open a connection, connectionsBeingCreatedCount
was incremented for the attempt but never decremented. The next query
then saw a connection still "being created", waited for it instead of
trying to connect again, and never resolved or called back.

Decrement the counter on the connection error path as well, before the
connectionError event is emitted, so waiting work retried from the error
handler sees the correct count.

Signed-off-by: Geoffrey Park <handsomeboy72@gmail.com>
STATEMENT_CLOSED_ERROR was declared as an instance field, but every use
reads it as Statement.STATEMENT_CLOSED_ERROR. That static lookup was
undefined, so calling prepare(), bind(), execute() and the other methods
on a closed Statement produced an Error with an empty message.

Declare it as a static class field so the error message is
"Statement has already been closed!".

Signed-off-by: Geoffrey Park <handsomeboy72@gmail.com>
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.

1 participant