diff --git a/core/src/main/java/com/linecorp/armeria/client/AbstractHttpRequestHandler.java b/core/src/main/java/com/linecorp/armeria/client/AbstractHttpRequestHandler.java index 68853d353b8..0c41b11e7f8 100644 --- a/core/src/main/java/com/linecorp/armeria/client/AbstractHttpRequestHandler.java +++ b/core/src/main/java/com/linecorp/armeria/client/AbstractHttpRequestHandler.java @@ -169,7 +169,7 @@ final boolean tryInitialize() { "Can't send requests. ID: " + id + ", session active: " + session.isAcquirable(responseDecoder.keepAliveHandler())); } - session.deactivate(); + session.markUnacquirable(); // No need to send RST because we didn't send any packet and this will be disconnected anyway. fail(UnprocessedRequestException.of(exception)); return false; @@ -223,7 +223,7 @@ final void writeHeaders(RequestHeaders headers) { // connection by sending a GOAWAY frame that will be sent after receiving the corresponding // response from the remote peer. The "Connection: close" header is stripped when it is converted to // a Netty HTTP/2 header. - session.deactivate(); + session.markUnacquirable(); } final ChannelPromise promise = ch.newPromise(); @@ -329,9 +329,11 @@ private void fail(Throwable cause) { } final void failAndReset(Throwable cause) { - // Mark the session as unhealthy so that subsequent requests do not use it. - final HttpSession session = HttpSession.get(ch); - session.deactivate(); + if (cause instanceof WriteTimeoutException) { + final HttpSession session = HttpSession.get(ch); + // Mark the session as unhealthy so that subsequent requests do not use it. + session.markUnacquirable(); + } if (cause instanceof ProxyConnectException || cause instanceof ResponseCompleteException) { // - ProxyConnectException is handled by HttpSessionHandler.exceptionCaught(). diff --git a/core/src/main/java/com/linecorp/armeria/client/Http1ResponseDecoder.java b/core/src/main/java/com/linecorp/armeria/client/Http1ResponseDecoder.java index 3e0f571e4ae..d1304716dcc 100644 --- a/core/src/main/java/com/linecorp/armeria/client/Http1ResponseDecoder.java +++ b/core/src/main/java/com/linecorp/armeria/client/Http1ResponseDecoder.java @@ -183,7 +183,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception } if (!HttpUtil.isKeepAlive(nettyRes)) { - session().deactivate(); + session().markUnacquirable(); } final HttpResponseWrapper res = getResponse(resId); diff --git a/core/src/main/java/com/linecorp/armeria/client/Http2ResponseDecoder.java b/core/src/main/java/com/linecorp/armeria/client/Http2ResponseDecoder.java index 147e976cfe3..26e2d076716 100644 --- a/core/src/main/java/com/linecorp/armeria/client/Http2ResponseDecoder.java +++ b/core/src/main/java/com/linecorp/armeria/client/Http2ResponseDecoder.java @@ -159,14 +159,14 @@ public void onStreamRemoved(Http2Stream stream) {} @Override public void onGoAwaySent(int lastStreamId, long errorCode, ByteBuf debugData) { - session().deactivate(); + session().markUnacquirable(); goAwayHandler.onGoAwaySent(channel(), lastStreamId, errorCode, debugData); } @Override public void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData) { // Should not reuse a connection that received a GOAWAY frame. - session().deactivate(); + session().markUnacquirable(); goAwayHandler.onGoAwayReceived(channel(), lastStreamId, errorCode, debugData); } diff --git a/core/src/main/java/com/linecorp/armeria/client/HttpClientPipelineConfigurator.java b/core/src/main/java/com/linecorp/armeria/client/HttpClientPipelineConfigurator.java index 6da8aea4a18..4937682bff0 100644 --- a/core/src/main/java/com/linecorp/armeria/client/HttpClientPipelineConfigurator.java +++ b/core/src/main/java/com/linecorp/armeria/client/HttpClientPipelineConfigurator.java @@ -805,7 +805,7 @@ private static final class ReadSuppressingAndChannelDeactivatingHandler extends @Override public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { - HttpSession.get(ctx.channel()).deactivate(); + HttpSession.get(ctx.channel()).markUnacquirable(); super.close(ctx, promise); } } diff --git a/core/src/main/java/com/linecorp/armeria/client/HttpSessionHandler.java b/core/src/main/java/com/linecorp/armeria/client/HttpSessionHandler.java index 6fcb5c129c5..01375220af8 100644 --- a/core/src/main/java/com/linecorp/armeria/client/HttpSessionHandler.java +++ b/core/src/main/java/com/linecorp/armeria/client/HttpSessionHandler.java @@ -327,7 +327,7 @@ public boolean isAcquirable(KeepAliveHandler keepAliveHandler) { } @Override - public void deactivate() { + public void markUnacquirable() { isAcquirable = false; } diff --git a/core/src/main/java/com/linecorp/armeria/client/WebSocketHttp1ClientChannelHandler.java b/core/src/main/java/com/linecorp/armeria/client/WebSocketHttp1ClientChannelHandler.java index baf4518234c..0b604248860 100644 --- a/core/src/main/java/com/linecorp/armeria/client/WebSocketHttp1ClientChannelHandler.java +++ b/core/src/main/java/com/linecorp/armeria/client/WebSocketHttp1ClientChannelHandler.java @@ -180,7 +180,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception } if (!HttpUtil.isKeepAlive(nettyRes)) { - session().deactivate(); + session().markUnacquirable(); } if (res == null && ArmeriaHttpUtil.isRequestTimeoutResponse(nettyRes)) { diff --git a/core/src/main/java/com/linecorp/armeria/internal/client/DefaultClientRequestContext.java b/core/src/main/java/com/linecorp/armeria/internal/client/DefaultClientRequestContext.java index 16bb7f4c01f..279b5d52218 100644 --- a/core/src/main/java/com/linecorp/armeria/internal/client/DefaultClientRequestContext.java +++ b/core/src/main/java/com/linecorp/armeria/internal/client/DefaultClientRequestContext.java @@ -1013,7 +1013,7 @@ public CompletableFuture initiateConnectionShutdown() { }); // To deactivate the channel when initiateShutdown is called after the RequestHeaders is sent. // The next request will trigger shutdown. - HttpSession.get(ch).deactivate(); + HttpSession.get(ch).markUnacquirable(); } }); return completableFuture; diff --git a/core/src/main/java/com/linecorp/armeria/internal/client/HttpSession.java b/core/src/main/java/com/linecorp/armeria/internal/client/HttpSession.java index 675400205ad..2b69160e015 100644 --- a/core/src/main/java/com/linecorp/armeria/internal/client/HttpSession.java +++ b/core/src/main/java/com/linecorp/armeria/internal/client/HttpSession.java @@ -17,6 +17,7 @@ package com.linecorp.armeria.internal.client; import com.linecorp.armeria.client.ClientRequestContext; +import com.linecorp.armeria.client.WriteTimeoutException; import com.linecorp.armeria.common.ClosedSessionException; import com.linecorp.armeria.common.HttpRequest; import com.linecorp.armeria.common.SerializationFormat; @@ -90,7 +91,7 @@ public boolean isAcquirable(KeepAliveHandler keepAliveHandler) { } @Override - public void deactivate() {} + public void markUnacquirable() {} @Override public int incrementAndGetNumRequestsSent() { @@ -137,9 +138,10 @@ static HttpSession get(Channel ch) { *
  • A connection is closed.
  • *
  • "Connection: close" header is sent or received.
  • *
  • A GOAWAY frame is sent or received.
  • + *
  • A {@link WriteTimeoutException} is raised
  • * */ - void deactivate(); + void markUnacquirable(); /** * Returns {@code true} if a new request can be sent with this {@link HttpSession}.