Skip to content

Cancel pool connection timeout timer when acquisition fails - #1712

Open
goutamadwant wants to merge 2 commits into
eclipse-vertx:masterfrom
goutamadwant:fix/pool-execute-timer-on-acquire-failure
Open

goutamadwant wants to merge 2 commits into
eclipse-vertx:masterfrom
goutamadwant:fix/pool-execute-timer-on-acquire-failure

Conversation

@goutamadwant

@goutamadwant goutamadwant commented Sep 27, 2026 •

Copy link
Copy Markdown

Motivation:

Fixes #1706

When the pool fails to acquire a connection, SqlConnectionPool.execute leaves the connection-timeout timer armed, so the query handler is completed twice:

  • Acquisition fails first: the timer fires later and fails the handler again with Timeout waiting for connection.
  • Timer fires first: the acquisition failure then fails the handler again.

Changes:

  • The acquisition-failure path now cancels the timer, as the success path already does.
  • If the timer has already fired, the handler is not completed again.

Tests (no database needed):

  • DriverBaseTest.testConnectFailureCancelsPoolConnectionTimeout
  • DriverBaseTest.testConnectFailureAfterPoolConnectionTimeout

Conformance:

You should have signed the Eclipse Contributor Agreement as explained in https://github.com/eclipse/vert.x/blob/master/CONTRIBUTING.md
Please also make sure you adhere to the code style guidelines: https://github.com/vert-x3/wiki/wiki/Vert.x-code-style-guidelines

See eclipse-vertx#1706

When a pooled query fails to acquire a connection, the connection timeout
timer is not cancelled, so it fails the query handler a second time when it
fires. When the timer fires first, the acquisition failure also fails the
handler again.

Handle the acquisition failure like a successful acquisition: cancel the
timer, and if it already fired, do not complete the handler again.

Signed-off-by: Goutam Adwant <workwithgoutam@gmail.com>
dequeueMetric(metric);
if (timerId != -1 && !vertx.cancelTimer(timerId)) {
// The timer already failed the handler
return Future.failedFuture(POOL_QUERY_TIMEOUT_EXCEPTION);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make it an if/else instead ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for checking @vietj done.

@vietj vietj added this to the 5.3.0 milestone Sep 28, 2026
Signed-off-by: Goutam Adwant <workwithgoutam@gmail.com>

This branch has not been deployed

No deployments
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.

SqlConnectionPool.execute() does not cancel the connection-timeout timer when acquire fails → IllegalStateException: Result is already complete

2 participants