Skip to content

Commit f4a5de0

Browse files
authored
Fix Connection Closing on Timeout (Azure#17690)
* Close connection when timeout occurs * Add CHANGELOG entry
1 parent ad184d3 commit f4a5de0

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

sdk/core/azure-core-http-netty/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 1.7.0-beta.1 (Unreleased)
44

5+
### Bug Fixes
6+
7+
- Fixed a bug where a connection would remain active when timed out instead of being closed.
58

69
## 1.6.3 (2020-10-29)
710

sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/ReadTimeoutHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public final class ReadTimeoutHandler extends ChannelInboundHandlerAdapter {
2323

2424
private final long timeoutMillis;
2525

26+
private boolean closed;
2627
private long lastReadMillis;
2728
private ScheduledFuture<?> readTimeoutWatcher;
2829

@@ -65,6 +66,10 @@ private void readTimeoutRunnable(ChannelHandlerContext ctx) {
6566
}
6667

6768
// No progress has been made since the last timeout event, channel has timed out.
68-
ctx.fireExceptionCaught(new TimeoutException(String.format(READ_TIMED_OUT_MESSAGE, timeoutMillis)));
69+
if (!closed) {
70+
ctx.fireExceptionCaught(new TimeoutException(String.format(READ_TIMED_OUT_MESSAGE, timeoutMillis)));
71+
ctx.close();
72+
closed = true;
73+
}
6974
}
7075
}

sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/ResponseTimeoutHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public final class ResponseTimeoutHandler extends ChannelInboundHandlerAdapter {
2323

2424
private final long timeoutMillis;
2525

26+
private boolean closed;
2627
private ScheduledFuture<?> responseTimeoutWatcher;
2728

2829
/**
@@ -51,6 +52,10 @@ public void handlerRemoved(ChannelHandlerContext ctx) {
5152
}
5253

5354
private void responseTimedOut(ChannelHandlerContext ctx) {
54-
ctx.fireExceptionCaught(new TimeoutException(String.format(RESPONSE_TIMED_OUT_MESSAGE, timeoutMillis)));
55+
if (!closed) {
56+
ctx.fireExceptionCaught(new TimeoutException(String.format(RESPONSE_TIMED_OUT_MESSAGE, timeoutMillis)));
57+
ctx.close();
58+
closed = true;
59+
}
5560
}
5661
}

sdk/core/azure-core-http-netty/src/main/java/com/azure/core/http/netty/implementation/WriteTimeoutHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public final class WriteTimeoutHandler extends ChannelOutboundHandlerAdapter {
2828

2929
private final long timeoutMillis;
3030

31+
private boolean closed;
3132
private long lastWriteMillis;
3233
private long lastWriteProgress;
3334
private ScheduledFuture<?> writeTimeoutWatcher;
@@ -83,6 +84,10 @@ private void writeTimeoutRunnable(ChannelHandlerContext ctx) {
8384
}
8485

8586
// No progress has been made since the last timeout event, channel has timed out.
86-
ctx.fireExceptionCaught(new TimeoutException(String.format(WRITE_TIMED_OUT_MESSAGE, timeoutMillis)));
87+
if (!closed) {
88+
ctx.fireExceptionCaught(new TimeoutException(String.format(WRITE_TIMED_OUT_MESSAGE, timeoutMillis)));
89+
ctx.close();
90+
closed = true;
91+
}
8792
}
8893
}

0 commit comments

Comments
 (0)