From 162bbbfe84fda396a6f4e2010de38a08e12883ec Mon Sep 17 00:00:00 2001 From: xjusko Date: Wed, 6 Mar 2024 15:57:46 +0100 Subject: [PATCH] [UNDERTOW-2249] Change that HttpClientConnection.sendRequest on a closed connection results in a ClosedChannelException instead of IOException --- .../main/java/io/undertow/client/UndertowClientMessages.java | 4 ++++ .../java/io/undertow/client/ajp/AjpClientConnection.java | 5 ++++- .../java/io/undertow/client/http/HttpClientConnection.java | 5 ++++- .../java/io/undertow/client/http/HttpClientTestCase.java | 4 ++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/io/undertow/client/UndertowClientMessages.java b/core/src/main/java/io/undertow/client/UndertowClientMessages.java index 8ef6984b53..2fc52edf1d 100644 --- a/core/src/main/java/io/undertow/client/UndertowClientMessages.java +++ b/core/src/main/java/io/undertow/client/UndertowClientMessages.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.net.URI; +import java.nio.channels.ClosedChannelException; /** * starting from 1000 @@ -74,4 +75,7 @@ public interface UndertowClientMessages { @Message(id = 1038, value = "Received invalid AJP chunk %s with response already complete") IOException receivedInvalidChunk(byte prefix); + + @Message(id = 1039, value = "Closed connection state") + ClosedChannelException closedConnectionState(); } diff --git a/core/src/main/java/io/undertow/client/ajp/AjpClientConnection.java b/core/src/main/java/io/undertow/client/ajp/AjpClientConnection.java index 8e2b2bc276..899d25a450 100644 --- a/core/src/main/java/io/undertow/client/ajp/AjpClientConnection.java +++ b/core/src/main/java/io/undertow/client/ajp/AjpClientConnection.java @@ -233,9 +233,12 @@ public void addCloseListener(ChannelListener listener) { @Override public void sendRequest(final ClientRequest request, final ClientCallback clientCallback) { - if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED | CLOSE_REQ | CLOSED)) { + if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED)) { clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState()); return; + } else if (anyAreSet(state, CLOSE_REQ | CLOSED)) { + clientCallback.failed(UndertowClientMessages.MESSAGES.closedConnectionState()); + return; } final AjpClientExchange AjpClientExchange = new AjpClientExchange(clientCallback, request, this); if (currentRequest == null) { diff --git a/core/src/main/java/io/undertow/client/http/HttpClientConnection.java b/core/src/main/java/io/undertow/client/http/HttpClientConnection.java index ec702d4d28..7d66368cf2 100644 --- a/core/src/main/java/io/undertow/client/http/HttpClientConnection.java +++ b/core/src/main/java/io/undertow/client/http/HttpClientConnection.java @@ -348,9 +348,12 @@ public void sendRequest(final ClientRequest request, final ClientCallback IoUtils.safeClose(connection)); DefaultServer.stopSSLServer();