Skip to content

Commit cee67d8

Browse files
committed
Connection managers to unwrap DeadlineTimeoutException from ExecutionException and propagate it to the caller
1 parent 08f3fdc commit cee67d8

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import org.apache.hc.core5.pool.StrictConnPool;
8585
import org.apache.hc.core5.util.Args;
8686
import org.apache.hc.core5.util.Deadline;
87+
import org.apache.hc.core5.util.DeadlineTimeoutException;
8788
import org.apache.hc.core5.util.Identifiable;
8889
import org.apache.hc.core5.util.TimeValue;
8990
import org.apache.hc.core5.util.Timeout;
@@ -388,6 +389,12 @@ public ConnectionEndpoint get(
388389
final PoolEntry<HttpRoute, ManagedHttpClientConnection> poolEntry;
389390
try {
390391
poolEntry = leaseFuture.get(timeout.getDuration(), timeout.getTimeUnit());
392+
} catch (final ExecutionException ex) {
393+
leaseFuture.cancel(true);
394+
if (ex.getCause() instanceof DeadlineTimeoutException) {
395+
throw (DeadlineTimeoutException) ex.getCause();
396+
}
397+
throw ex;
391398
} catch (final TimeoutException ex) {
392399
leaseFuture.cancel(true);
393400
throw ex;

httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
import org.apache.hc.core5.reactor.ssl.TlsDetails;
9696
import org.apache.hc.core5.util.Args;
9797
import org.apache.hc.core5.util.Deadline;
98+
import org.apache.hc.core5.util.DeadlineTimeoutException;
9899
import org.apache.hc.core5.util.Identifiable;
99100
import org.apache.hc.core5.util.TimeValue;
100101
import org.apache.hc.core5.util.Timeout;
@@ -401,7 +402,18 @@ public AsyncConnectionEndpoint get() throws InterruptedException, ExecutionExcep
401402
@Override
402403
public AsyncConnectionEndpoint get(
403404
final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
404-
return resultFuture.get(timeout, unit);
405+
try {
406+
return resultFuture.get(timeout, unit);
407+
} catch (final ExecutionException ex) {
408+
leaseFuture.cancel(true);
409+
if (ex.getCause() instanceof DeadlineTimeoutException) {
410+
throw (DeadlineTimeoutException) ex.getCause();
411+
}
412+
throw ex;
413+
} catch (final TimeoutException ex) {
414+
leaseFuture.cancel(true);
415+
throw ex;
416+
}
405417
}
406418

407419
@Override

0 commit comments

Comments
 (0)