Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/core/azure-core-http-netty/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public final class ReadTimeoutHandler extends ChannelInboundHandlerAdapter {

private final long timeoutMillis;

private boolean closed;
private long lastReadMillis;
private ScheduledFuture<?> readTimeoutWatcher;

Expand Down Expand Up @@ -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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this check required? Can this method be called multiple times? If yes, what's the impact of trying to close the context each time?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check is there to ensure that we don't fire the exception multiple times. As for what happens if close is called multiple times I am not certain and can take a look into this.

@alzimmermsft alzimmermsft Nov 20, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked into the safety of calling close multiple times and the answer is unknown as this will trigger the close handler for other handlers, so it would be dependent on the configuration of the Netty pipeline. In our default instance it is safe to call multiple times but that isn't a guarantee.

ctx.fireExceptionCaught(new TimeoutException(String.format(READ_TIMED_OUT_MESSAGE, timeoutMillis)));
ctx.close();
closed = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public final class ResponseTimeoutHandler extends ChannelInboundHandlerAdapter {

private final long timeoutMillis;

private boolean closed;
private ScheduledFuture<?> responseTimeoutWatcher;

/**
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}