From d8d7ad37a31a3aaf30eea5c08c1109aa5b3ca316 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Wed, 28 Apr 2021 16:31:16 +0200 Subject: [PATCH] Extra sage-guards for concurrent connection endpoint acquisition and request execution cancellation --- .../hc/client5/http/impl/classic/InternalExecRuntime.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalExecRuntime.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalExecRuntime.java index a3442653d..ba0d0d1b3 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalExecRuntime.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalExecRuntime.java @@ -103,11 +103,11 @@ public void acquireEndpoint( final LeaseRequest connRequest = manager.lease(id, route, connectionRequestTimeout, object); state = object; if (cancellableDependency != null) { + cancellableDependency.setDependency(connRequest); if (cancellableDependency.isCancelled()) { connRequest.cancel(); throw new RequestFailedException("Request aborted"); } - cancellableDependency.setDependency(connRequest); } try { final ConnectionEndpoint connectionEndpoint = connRequest.get(connectionRequestTimeout); @@ -115,6 +115,10 @@ public void acquireEndpoint( reusable = connectionEndpoint.isConnected(); if (cancellableDependency != null) { cancellableDependency.setDependency(this); + if (cancellableDependency.isCancelled()) { + cancel(); + throw new RequestFailedException("Request aborted"); + } } if (log.isDebugEnabled()) { log.debug("{} acquired endpoint {}", id, ConnPoolSupport.getId(connectionEndpoint));