Skip to content

Commit 11a5225

Browse files
committed
[UNDERTOW-2249] At ClientConnection, use ClosedChannelException to notify clientCallback instead of IOException complaining of invalid connection state. At HttpClientTestCase.testSslServerIdentity, enforce that the exception received is ClosedChannelException
Signed-off-by: Flavia Rainone <[email protected]>
1 parent 15e5454 commit 11a5225

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

core/src/main/java/io/undertow/client/ajp/AjpClientConnection.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,14 @@ public void addCloseListener(ChannelListener<ClientConnection> listener) {
233233

234234
@Override
235235
public void sendRequest(final ClientRequest request, final ClientCallback<ClientExchange> clientCallback) {
236-
if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED | CLOSE_REQ | CLOSED)) {
236+
if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED)) {
237237
clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState());
238238
return;
239239
}
240+
if (anyAreSet(state, CLOSE_REQ | CLOSED)) {
241+
clientCallback.failed(new ClosedChannelException());
242+
return;
243+
}
240244
final AjpClientExchange AjpClientExchange = new AjpClientExchange(clientCallback, request, this);
241245
if (currentRequest == null) {
242246
initiateRequest(AjpClientExchange);

core/src/main/java/io/undertow/client/http/HttpClientConnection.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,14 @@ public void sendRequest(final ClientRequest request, final ClientCallback<Client
348348
http2Delegate.sendRequest(request, clientCallback);
349349
return;
350350
}
351-
if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED | CLOSE_REQ | CLOSED)) {
351+
if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED)) {
352352
clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState());
353353
return;
354354
}
355+
if (anyAreSet(state, CLOSE_REQ | CLOSED)) {
356+
clientCallback.failed(new ClosedChannelException());
357+
return;
358+
}
355359
final HttpClientExchange httpClientExchange = new HttpClientExchange(clientCallback, request, this);
356360
boolean ssl = this.connection instanceof SslConnection;
357361
if(!ssl && !http2Tried && options.get(UndertowOptions.ENABLE_HTTP2, false) && !request.getRequestHeaders().contains(Headers.UPGRADE)) {

core/src/test/java/io/undertow/client/http/HttpClientTestCase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,7 @@ public void testSslServerIdentity() throws Exception {
360360
latch.await(10, TimeUnit.SECONDS);
361361

362362
Assert.assertEquals(0, responses.size());
363-
// see UNDERTOW-2249: assert exception instanceof ClosedChannelException
364-
Assert.assertNotNull(exception);
363+
Assert.assertTrue(exception instanceof ClosedChannelException);
365364
} finally {
366365
connection.getIoThread().execute(() -> IoUtils.safeClose(connection));
367366
DefaultServer.stopSSLServer();

0 commit comments

Comments
 (0)