From a342b4ca55acbd23732db43cb07d8c5b35b27b5c Mon Sep 17 00:00:00 2001 From: Ryan Schmitt Date: Wed, 28 Jan 2026 18:52:33 -0800 Subject: [PATCH] LaxConnPool: Loop over expired connections This change brings `LaxConnPool` into alignment with `StrictConnPool`, which loops over pool entries and discards expired ones as they are discovered, instead of returning them. --- .../main/java/org/apache/hc/core5/pool/LaxConnPool.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java b/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java index 15405ac8b9..c3e682b66d 100644 --- a/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java +++ b/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java @@ -442,13 +442,11 @@ private PoolEntry getAvailableEntry(final Object state) { final PoolEntry entry = ref.getReference(); if (ref.compareAndSet(entry, entry, false, true)) { it.remove(); - if (entry.getExpiryDeadline().isExpired()) { + if (entry.getExpiryDeadline().isExpired() || !Objects.equals(entry.getState(), state)) { entry.discardConnection(CloseMode.GRACEFUL); + } else { + return entry; } - if (!Objects.equals(entry.getState(), state)) { - entry.discardConnection(CloseMode.GRACEFUL); - } - return entry; } } return null;