diff --git a/sdk/core/azure-core-http-netty/CHANGELOG.md b/sdk/core/azure-core-http-netty/CHANGELOG.md index b1566a1d9452..d84152b883bd 100644 --- a/sdk/core/azure-core-http-netty/CHANGELOG.md +++ b/sdk/core/azure-core-http-netty/CHANGELOG.md @@ -2,6 +2,9 @@ ## 1.7.0-beta.1 (Unreleased) +### Bug Fixes + +- Fixed a bug where a connection would remain active when timed out instead of being closed. ## 1.6.3 (2020-10-29) diff --git a/sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/ReadTimeoutHandler.java b/sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/ReadTimeoutHandler.java index e19332885fd9..928fdb8bcef2 100644 --- a/sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/ReadTimeoutHandler.java +++ b/sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/ReadTimeoutHandler.java @@ -23,6 +23,7 @@ public final class ReadTimeoutHandler extends ChannelInboundHandlerAdapter { private final long timeoutMillis; + private boolean closed; private long lastReadMillis; private ScheduledFuture readTimeoutWatcher; @@ -65,6 +66,10 @@ private void readTimeoutRunnable(ChannelHandlerContext ctx) { } // No progress has been made since the last timeout event, channel has timed out. - ctx.fireExceptionCaught(new TimeoutException(String.format(READ_TIMED_OUT_MESSAGE, timeoutMillis))); + if (!closed) { + ctx.fireExceptionCaught(new TimeoutException(String.format(READ_TIMED_OUT_MESSAGE, timeoutMillis))); + ctx.close(); + closed = true; + } } } diff --git a/sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/ResponseTimeoutHandler.java b/sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/ResponseTimeoutHandler.java index d42f8692ec04..b95afbf5f5b2 100644 --- a/sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/ResponseTimeoutHandler.java +++ b/sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/ResponseTimeoutHandler.java @@ -23,6 +23,7 @@ public final class ResponseTimeoutHandler extends ChannelInboundHandlerAdapter { private final long timeoutMillis; + private boolean closed; private ScheduledFuture responseTimeoutWatcher; /** @@ -51,6 +52,10 @@ public void handlerRemoved(ChannelHandlerContext ctx) { } private void responseTimedOut(ChannelHandlerContext ctx) { - ctx.fireExceptionCaught(new TimeoutException(String.format(RESPONSE_TIMED_OUT_MESSAGE, timeoutMillis))); + if (!closed) { + ctx.fireExceptionCaught(new TimeoutException(String.format(RESPONSE_TIMED_OUT_MESSAGE, timeoutMillis))); + ctx.close(); + closed = true; + } } } diff --git a/sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/WriteTimeoutHandler.java b/sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/WriteTimeoutHandler.java index bbd297705210..5b817047d72e 100644 --- a/sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/WriteTimeoutHandler.java +++ b/sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/WriteTimeoutHandler.java @@ -28,6 +28,7 @@ public final class WriteTimeoutHandler extends ChannelOutboundHandlerAdapter { private final long timeoutMillis; + private boolean closed; private long lastWriteMillis; private long lastWriteProgress; private ScheduledFuture writeTimeoutWatcher; @@ -83,6 +84,10 @@ private void writeTimeoutRunnable(ChannelHandlerContext ctx) { } // No progress has been made since the last timeout event, channel has timed out. - ctx.fireExceptionCaught(new TimeoutException(String.format(WRITE_TIMED_OUT_MESSAGE, timeoutMillis))); + if (!closed) { + ctx.fireExceptionCaught(new TimeoutException(String.format(WRITE_TIMED_OUT_MESSAGE, timeoutMillis))); + ctx.close(); + closed = true; + } } }