Repository navigation
fix: Pool connect-failure handling and empty closed-Statement error message - #505
Open
younjungpark wants to merge 3 commits into
Open
younjungpark wants to merge 3 commits into
younjungpark wants to merge 3 commits into
Conversation
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>
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.
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 connectWith 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 (onprocess.nextTick, like the success path).2. Pool waits forever after a failed connection attempt
connectionsBeingCreatedCountwas incremented for each attempt but only decremented on success. After one failed attempt, the nextquery()/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, beforeconnectionErroris emitted, so work retried from that handler sees the correct count.3. Errors from a closed
Statementhave an empty messageSTATEMENT_CLOSED_ERRORwas an instance field, but the code readsStatement.STATEMENT_CLOSED_ERROR, which wasundefined.prepare(),bind(),execute(), etc. on a closed statement therefore threw/returnednew Error(undefined). It is now astaticfield, so the message isStatement has already been closed!. (The instance propertystatement.STATEMENT_CLOSED_ERRORis gone; it was not part of the typings or docs.)Tests
test/pool/query.test.js: connection-failure tests useDRIVER=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 afterclose()(callback and Promise). Without the fix, the message is''.