Skip to content

Commit b88802e

Browse files
committed
Have SQL connection pool handle racy uncancellable timeout.
Motivation: The SQL connection pool resource acquisition completion can race against the acquisition timeout. Changes: When the acquisition timeout cannot be cancelled, the resource should be recycled and the promise should not be completed.
1 parent bf228b8 commit b88802e

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/pool/SqlConnectionPool.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -267,24 +267,25 @@ class PoolRequest implements PoolWaiter.Listener<PooledConnection>, Completable<
267267

268268
@Override
269269
public void complete(Lease<PooledConnection> lease, Throwable failure) {
270-
if (timerID != -1L) {
271-
vertx.cancelTimer(timerID);
272-
}
273-
if (failure == null) {
274-
if (afterAcquire != null) {
275-
afterAcquire.apply(lease.get().conn).onComplete(ar2 -> {
276-
if (ar2.succeeded()) {
277-
handle(lease);
278-
} else {
279-
// Should we do some cleanup ?
280-
handler.fail(failure);
281-
}
282-
});
270+
if (timerID != -1L && !vertx.cancelTimer(timerID)) {
271+
lease.recycle();
272+
} else {
273+
if (failure == null) {
274+
if (afterAcquire != null) {
275+
afterAcquire.apply(lease.get().conn).onComplete(ar2 -> {
276+
if (ar2.succeeded()) {
277+
handle(lease);
278+
} else {
279+
// Should we do some cleanup ?
280+
handler.fail(failure);
281+
}
282+
});
283+
} else {
284+
handle(lease);
285+
}
283286
} else {
284-
handle(lease);
287+
handler.fail(failure);
285288
}
286-
} else {
287-
handler.fail(failure);
288289
}
289290
}
290291

0 commit comments

Comments
 (0)