From 9a12e0b27f38fd82b6c41155713859860c058c37 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Wed, 13 Mar 2024 12:06:17 +0100 Subject: [PATCH] The Http1xClientConnection will not fail the pending stream allocation 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. --- .../http/impl/Http1xClientConnection.java | 1 + .../java/io/vertx/core/http/Http1xTest.java | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/main/java/io/vertx/core/http/impl/Http1xClientConnection.java b/src/main/java/io/vertx/core/http/impl/Http1xClientConnection.java index c63a7fec396..3f7a3141cad 100644 --- a/src/main/java/io/vertx/core/http/impl/Http1xClientConnection.java +++ b/src/main/java/io/vertx/core/http/impl/Http1xClientConnection.java @@ -719,6 +719,7 @@ void handleException(Throwable cause) { void handleClosed(Throwable err) { if (err != null) { handleException(err); + promise.tryFail(err); } if (!closed) { closed = true; diff --git a/src/test/java/io/vertx/core/http/Http1xTest.java b/src/test/java/io/vertx/core/http/Http1xTest.java index f79f25fb985..94eefd7e37f 100644 --- a/src/test/java/io/vertx/core/http/Http1xTest.java +++ b/src/test/java/io/vertx/core/http/Http1xTest.java @@ -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 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(); + } }