Skip to content

Commit

Permalink
The Http1xClientConnection will not fail the pending stream allocatio…
Browse files Browse the repository at this point in the history
…n requests when the connection is closed. The stream handle closed method does ignore the stream allocation request promise assuming that it is always succeeded. When a stream it closed with a failure the stream allocation request promise should be attempted to be failed.

Update the Http1xClientConnection stream implementation to fail the promise when the stream is closed with an exception.
  • Loading branch information
vietj committed Mar 13, 2024
1 parent 874a2ba commit 9a12e0b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ void handleException(Throwable cause) {
void handleClosed(Throwable err) {
if (err != null) {
handleException(err);
promise.tryFail(err);
}
if (!closed) {
closed = true;
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/io/vertx/core/http/Http1xTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5438,4 +5438,39 @@ public void testRecycleConnectionOnRequestEnd() throws Exception {
}
await();
}

@Test
public void testFailPendingRequestAllocationWhenConnectionIsClosed() throws Exception {
waitFor(2);
server.requestHandler(request -> {
HttpServerResponse resp = request.response();
resp.end().onComplete(onSuccess(v -> {
request.connection().close();
}));
});
startServer(testAddress);
client.close();
client = vertx.createHttpClient(new HttpClientOptions().setPipelining(true), new PoolOptions().setHttp1MaxSize(1));
for (int i = 0;i < 2;i++) {
int val = i;
Future<HttpClientRequest> fut = client.request(requestOptions);
fut.onComplete(ar -> {
switch (val) {
case 0:
assertTrue(ar.succeeded());
HttpClientRequest req = ar.result();
req.sendHead();
req.response().onComplete(onSuccess(resp -> {
complete();
}));
break;
case 1:
assertTrue(ar.failed());
complete();
break;
}
});
}
await();
}
}

0 comments on commit 9a12e0b

Please sign in to comment.