Skip to content

Commit 24ccaad

Browse files
committed
Mark HTTP/1.1 async connection as not open (non-reusable) as soon as it becomes closed by the opposite endpoint
1 parent a5b00b3 commit 24ccaad

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ private enum ConnectionState { READY, ACTIVE, GRACEFUL_SHUTDOWN, SHUTDOWN}
105105

106106
private volatile ProtocolVersion version;
107107
private volatile EndpointDetails endpointDetails;
108+
private volatile boolean endOfStream;
108109

109110
AbstractHttp1StreamDuplexer(
110111
final ProtocolIOSession ioSession,
@@ -265,6 +266,17 @@ IncomingMessage parseMessageHead(final boolean endOfStream) throws IOException,
265266
return messageHead;
266267
}
267268

269+
private int fillBuffer() throws IOException {
270+
final int bytesRead = inbuf.fill(ioSession);
271+
if (bytesRead > 0) {
272+
inTransportMetrics.incrementBytesTransferred(bytesRead);
273+
}
274+
if (bytesRead == -1) {
275+
endOfStream = true;
276+
}
277+
return bytesRead;
278+
}
279+
268280
public final void onInput(final ByteBuffer src) throws HttpException, IOException {
269281
if (src != null) {
270282
final int n = src.remaining();
@@ -277,13 +289,8 @@ public final void onInput(final ByteBuffer src) throws HttpException, IOExceptio
277289
return;
278290
}
279291

280-
boolean endOfStream = false;
281292
if (incomingMessage == null) {
282-
final int bytesRead = inbuf.fill(ioSession);
283-
if (bytesRead > 0) {
284-
inTransportMetrics.incrementBytesTransferred(bytesRead);
285-
}
286-
endOfStream = bytesRead == -1;
293+
fillBuffer();
287294
}
288295

289296
do {
@@ -342,6 +349,7 @@ public final void onInput(final ByteBuffer src) throws HttpException, IOExceptio
342349
incomingMessage = null;
343350
ioSession.setEvent(SelectionKey.OP_READ);
344351
inputEnd();
352+
fillBuffer();
345353
} else if (bytesRead == 0) {
346354
break;
347355
}
@@ -561,7 +569,7 @@ public void close(final CloseMode closeMode) {
561569

562570
@Override
563571
public boolean isOpen() {
564-
return connState.compareTo(ConnectionState.ACTIVE) <= 0;
572+
return connState.compareTo(ConnectionState.ACTIVE) <= 0 && !endOfStream;
565573
}
566574

567575
@Override

0 commit comments

Comments
 (0)