Skip to content

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

Description

@Rene2000k

Version

4.5.34

Context

When the database is unreachable and a query is executed through the pool (Pool#query(...).execute() / preparedQuery), the caller correctly receives the connection error. However, once the pool connection timeout elapses, Vert.x reports an uncaught exception:

java.lang.IllegalStateException: Result is already complete
    at io.vertx.core.Promise.fail(Promise.java:90)
    at io.vertx.sqlclient.impl.pool.SqlConnectionPool.lambda$execute$3(SqlConnectionPool.java:216)
    at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(...)
    ...

In SqlConnectionPool.execute(ContextInternal, CommandBase<R>, long timeout):

  1. If timeout > 0, a timer is registered that calls res.fail(POOL_QUERY_TIMEOUT_EXCEPTION).
  2. The timer is only cancelled in the success branch of p.future().compose(lease -> ...).
  3. In the failure branch (t -> { dequeueAndReject(...); return Future.failedFuture(t); }) the timer is not cancelled; onComplete then calls res.fail(ar.cause()).
  4. When the timer later fires, res.fail(...) is invoked on an already completed promise → IllegalStateException.

This is deterministic: every acquire failure that happens before the timeout expires produces the exception exactly timeout ms later.

Steps to reproduce

  1. Create a Pool with PoolOptions#setConnectionTimeout(2) (seconds) pointing to an unreachable host/port (or a stopped PostgreSQL container).
  2. Execute a query via the pool; it fails with the connection error (expected).
  3. Wait ~3 seconds without further requests.
  4. Observe the uncaught IllegalStateException from the timer handler.

Do you have a reproducer?

https://gist.github.com/Rene2000k/8e0e0a2aaec8fdd13e6ba8e567bdd301

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions