From e7b2464e4b12ebd9757ae720af3e84c601abef75 Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Wed, 18 Nov 2020 13:25:27 -0800 Subject: [PATCH 1/2] Close connection when timeout occurs --- .../core/http/netty/implementation/ReadTimeoutHandler.java | 7 ++++++- .../http/netty/implementation/ResponseTimeoutHandler.java | 7 ++++++- .../http/netty/implementation/WriteTimeoutHandler.java | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) 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; + } } } From b474fa01e1dabaa6d9857238e9edda115e617892 Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Thu, 19 Nov 2020 12:52:21 -0800 Subject: [PATCH 2/2] Add CHANGELOG entry --- sdk/core/azure-core-http-netty/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) 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)