Skip to content

Commit 168e7b2

Browse files
committed
PoolingAsyncClientConnectionManager: Use StaleCheckCommand
1 parent a8a04b1 commit 168e7b2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.apache.hc.core5.http.nio.AsyncPushConsumer;
7171
import org.apache.hc.core5.http.nio.HandlerFactory;
7272
import org.apache.hc.core5.http.nio.command.RequestExecutionCommand;
73+
import org.apache.hc.core5.http.nio.command.StaleCheckCommand;
7374
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
7475
import org.apache.hc.core5.http.protocol.HttpContext;
7576
import org.apache.hc.core5.http2.HttpVersionPolicy;
@@ -326,6 +327,17 @@ public void completed(final PoolEntry<HttpRoute, ManagedAsyncClientConnection> p
326327
leaseCompleted(poolEntry);
327328
})), Command.Priority.IMMEDIATE);
328329
return;
330+
} else {
331+
connection.submitCommand(new StaleCheckCommand(result -> {
332+
if (!Boolean.TRUE.equals(result)) {
333+
if (LOG.isDebugEnabled()) {
334+
LOG.debug("{} connection {} is stale", id, ConnPoolSupport.getId(connection));
335+
}
336+
poolEntry.discardConnection(CloseMode.GRACEFUL);
337+
}
338+
leaseCompleted(poolEntry);
339+
}), Command.Priority.IMMEDIATE);
340+
return;
329341
}
330342
}
331343
}

0 commit comments

Comments
 (0)