Skip to content

Commit 7d37f45

Browse files
committed
early quit if is not reusable
1 parent 4471203 commit 7d37f45

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ PoolEntry<T, C> lease() {
290290
long release(final PoolEntry<T, C> entry, final boolean reusable) {
291291
lock.lock();
292292
try {
293+
if (!reusable) {
294+
entry.discardConnection(CloseMode.GRACEFUL);
295+
}
296+
293297
final AtomicLong counter = entryMap.compute(entry, (e, c) -> {
294298
if (c == null) {
295299
return null;

httpclient5/src/test/java/org/apache/hc/client5/http/impl/nio/H2SharingConnPoolTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ void testReleaseNonReusableNotInCacheReturnedToPool() throws Exception {
345345
}).when(connPool).release(Mockito.eq(poolEntry), Mockito.anyBoolean());
346346

347347
h2SharingPool.release(poolEntry, false);
348-
h2SharingPool.release(poolEntry, false);
348+
// for reproduce https://issues.apache.org/jira/browse/HTTPCLIENT-2379
349349
Assertions.assertThrows(IllegalStateException.class, () -> h2SharingPool.release(poolEntry, false));
350350
}
351351

0 commit comments

Comments
 (0)