Skip to content

Commit dfa2cd5

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 dfa2cd5

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

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

Lines changed: 15 additions & 10 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,17 +289,9 @@ public final void onInput(final ByteBuffer src) throws HttpException, IOExceptio
277289
return;
278290
}
279291

280-
boolean endOfStream = false;
281-
if (incomingMessage == null) {
282-
final int bytesRead = inbuf.fill(ioSession);
283-
if (bytesRead > 0) {
284-
inTransportMetrics.incrementBytesTransferred(bytesRead);
285-
}
286-
endOfStream = bytesRead == -1;
287-
}
288-
289292
do {
290293
if (incomingMessage == null) {
294+
fillBuffer();
291295

292296
final IncomingMessage messageHead = parseMessageHead(endOfStream);
293297
if (messageHead != null) {
@@ -342,6 +346,7 @@ public final void onInput(final ByteBuffer src) throws HttpException, IOExceptio
342346
incomingMessage = null;
343347
ioSession.setEvent(SelectionKey.OP_READ);
344348
inputEnd();
349+
fillBuffer();
345350
} else if (bytesRead == 0) {
346351
break;
347352
}
@@ -561,7 +566,7 @@ public void close(final CloseMode closeMode) {
561566

562567
@Override
563568
public boolean isOpen() {
564-
return connState.compareTo(ConnectionState.ACTIVE) <= 0;
569+
return connState.compareTo(ConnectionState.ACTIVE) <= 0 && !endOfStream;
565570
}
566571

567572
@Override

0 commit comments

Comments
 (0)