8221395: HttpClient leaving connections in CLOSE_WAIT state until Java process ends

When a non WebSocket connection is not returned to the pool, it needs to be closed even if HttpConnection::isOpen yields false.

Reviewed-by: chegar, michaelm
This commit is contained in:
Daniel Fuchs 2019-03-28 12:16:36 +00:00
parent 76cdc8016f
commit 47b9d898ab
3 changed files with 232 additions and 18 deletions

View file

@ -317,14 +317,13 @@ abstract class HttpConnection implements Closeable {
void closeOrReturnToCache(HttpHeaders hdrs) {
if (hdrs == null) {
// the connection was closed by server, eof
Log.logTrace("Cannot return connection to pool: closing {0}", this);
close();
return;
}
if (!isOpen()) {
return;
}
HttpClientImpl client = client();
if (client == null) {
Log.logTrace("Client released: closing {0}", this);
close();
return;
}
@ -333,10 +332,12 @@ abstract class HttpConnection implements Closeable {
.map((s) -> !s.equalsIgnoreCase("close"))
.orElse(true);
if (keepAlive) {
if (keepAlive && isOpen()) {
Log.logTrace("Returning connection to the pool: {0}", this);
pool.returnToPool(this);
} else {
Log.logTrace("Closing connection (keepAlive={0}, isOpen={1}): {2}",
keepAlive, isOpen(), this);
close();
}
}