Skip to content

Commit

Permalink
HTTP/1.1 stream close handler can be called twice leading to recyclin…
Browse files Browse the repository at this point in the history
…g the connection to the pool more than it should - fixes #4076
vietj committed Aug 23, 2021
1 parent 5c048b0 commit 7ad3e50
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/main/java/io/vertx/core/http/impl/Http1xClientConnection.java
Original file line number Diff line number Diff line change
@@ -350,6 +350,7 @@ private static class StreamImpl extends Stream implements HttpClientStream {
private final InboundBuffer<Object> queue;
private boolean reset;
private boolean writable;
private boolean closed;
private HttpRequestHead request;
private Handler<HttpResponseHead> headHandler;
private Handler<Buffer> chunkHandler;
@@ -585,9 +586,7 @@ void handleChunk(Buffer buff) {

void handleEnd(LastHttpContent trailer) {
queue.write(new HeadersAdaptor(trailer.trailingHeaders()));
if (closeHandler != null) {
closeHandler.handle(null);
}
tryClose();
}

void handleException(Throwable cause) {
@@ -599,8 +598,18 @@ void handleException(Throwable cause) {
@Override
void handleClosed() {
handleException(CLOSED_EXCEPTION);
if (closeHandler != null) {
closeHandler.handle(null);
tryClose();
}

/**
* Attempt to close the stream.
*/
private void tryClose() {
if (!closed) {
closed = true;
if (closeHandler != null) {
closeHandler.handle(null);
}
}
}
}

0 comments on commit 7ad3e50

Please sign in to comment.