Skip to content

Mark HTTP/1.1 async connection as not open (non-reusable) as soon as it becomes closed by the opposite endpoint #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private enum ConnectionState { READY, ACTIVE, GRACEFUL_SHUTDOWN, SHUTDOWN}

private volatile ProtocolVersion version;
private volatile EndpointDetails endpointDetails;
private volatile boolean endOfStream;

AbstractHttp1StreamDuplexer(
final ProtocolIOSession ioSession,
Expand Down Expand Up @@ -265,6 +266,17 @@ IncomingMessage parseMessageHead(final boolean endOfStream) throws IOException,
return messageHead;
}

private int fillBuffer() throws IOException {
final int bytesRead = inbuf.fill(ioSession);
if (bytesRead > 0) {
inTransportMetrics.incrementBytesTransferred(bytesRead);
}
if (bytesRead == -1) {
endOfStream = true;
}
return bytesRead;
}

public final void onInput(final ByteBuffer src) throws HttpException, IOException {
if (src != null) {
final int n = src.remaining();
Expand All @@ -277,17 +289,9 @@ public final void onInput(final ByteBuffer src) throws HttpException, IOExceptio
return;
}

boolean endOfStream = false;
if (incomingMessage == null) {
final int bytesRead = inbuf.fill(ioSession);
if (bytesRead > 0) {
inTransportMetrics.incrementBytesTransferred(bytesRead);
}
endOfStream = bytesRead == -1;
}

do {
if (incomingMessage == null) {
fillBuffer();

final IncomingMessage messageHead = parseMessageHead(endOfStream);
if (messageHead != null) {
Expand Down Expand Up @@ -342,6 +346,7 @@ public final void onInput(final ByteBuffer src) throws HttpException, IOExceptio
incomingMessage = null;
ioSession.setEvent(SelectionKey.OP_READ);
inputEnd();
fillBuffer();
} else if (bytesRead == 0) {
break;
}
Expand Down Expand Up @@ -561,7 +566,7 @@ public void close(final CloseMode closeMode) {

@Override
public boolean isOpen() {
return connState.compareTo(ConnectionState.ACTIVE) <= 0;
return connState.compareTo(ConnectionState.ACTIVE) <= 0 && !endOfStream;
}

@Override
Expand Down
Loading