Skip to content

Cancel pool connection timeout timer when acquisition fails - #1712

Merged
tsegismont merged 2 commits into
eclipse-vertx:masterfrom
goutamadwant:fix/pool-execute-timer-on-acquire-failure
Oct 8, 2026
Merged

tsegismont merged 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
Contributor

See #1706

When SqlConnectionPool.execute fails to acquire a connection, the connection-timeout timer is left armed. The timer later fires and calls handler.fail on an already-completed promise, throwing IllegalStateException: Result is already complete.

The success path already cancels the timer (added in #1586) and handles the race when the timer fires first (added in e290886). The failure path was missing both: it neither cancelled the timer nor guarded against the timer having already fired.

The fix mirrors the success-path pattern: attempt to cancel the timer in the failure branch. If cancelTimer returns false (the timer already fired and completed the handler), propagate POOL_QUERY_TIMEOUT_EXCEPTION so the existing guard in onComplete skips the redundant handler.fail.

Tests cover both race orderings — acquisition fails before the timer, and timer fires before acquisition fails — without requiring a database.

@vietj vietj added this to the 5.3.0 milestone Sep 28, 2026
@vietj

vietj commented Sep 30, 2026

Copy link
Copy Markdown
Member

@goutamadwant can you make it a single commit with a proper commit message ?

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>
Signed-off-by: Goutam Adwant <workwithgoutam@gmail.com>
@tsegismont
tsegismont force-pushed the fix/pool-execute-timer-on-acquire-failure branch from 5bdbcd0 to 1edf65c Compare October 8, 2026 13:13

@tsegismont tsegismont left a comment

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.

LGTM, thank you @goutamadwant

@tsegismont
tsegismont merged commit 3967b19 into eclipse-vertx:master Oct 8, 2026
20 checks passed
tsegismont added a commit that referenced this pull request Oct 8, 2026
…1750)

* Cancel pool connection timeout timer when acquisition fails

See #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.



* Use if/else in the acquisition failure branch



---------

Signed-off-by: Goutam Adwant <workwithgoutam@gmail.com>
Co-authored-by: Goutam Adwant <8672451+goutamadwant@users.noreply.github.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.

3 participants