Skip to content

Commit 9ba90bb

Browse files
committed
Address feedback
1 parent 61a1147 commit 9ba90bb

5 files changed

Lines changed: 20 additions & 21 deletions

File tree

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/NettyRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ private void addWriteTimeoutHandlers() {
297297
new IdleStateHandler(0, context.configuration().writeTimeoutMillis(), 0,
298298
TimeUnit.MILLISECONDS));
299299
channel.pipeline().addBefore(httpStreamsName, null,
300-
new WriteIdleTimeoutHandler());
300+
new WriteIdleTimeoutHandler(context.configuration().writeTimeoutMillis()));
301301
}
302302

303303
/**

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/WriteIdleTimeoutHandler.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@
2929
*/
3030
@SdkInternalApi
3131
public final class WriteIdleTimeoutHandler extends ChannelDuplexHandler {
32+
private final long timeoutMillis;
3233
private boolean closed;
3334

35+
public WriteIdleTimeoutHandler(long timeoutMillis) {
36+
this.timeoutMillis = timeoutMillis;
37+
}
38+
3439
@Override
3540
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
3641
if (evt instanceof IdleStateEvent) {
@@ -42,21 +47,15 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
4247
super.userEventTriggered(ctx, evt);
4348
}
4449

45-
private void writeTimeout(ChannelHandlerContext ctx) throws Exception {
50+
private void writeTimeout(ChannelHandlerContext ctx) {
4651
if (!closed) {
47-
IOException exception = new IOException(
48-
errorMessageWithChannelDiagnostics(ctx.channel(), "No data was written to the request body for the configured "
49-
+ "write timeout duration. "
50-
+ "This can occur if the request body publisher is slow to "
51-
+ "produce data, "
52-
+ "for example when using AsyncRequestBody.fromInputStream() "
53-
+ "with an executor "
54-
+ "that has fewer threads than concurrent requests. "
55-
+ "If applicable, consider increasing the executor's thread "
56-
+ "pool size or "
57-
+ "investigating what is preventing the request body from "
58-
+ "being written."));
59-
ctx.fireExceptionCaught(exception);
52+
String message = String.format("No data was written to the request body within %dms. "
53+
+ "This can occur if the request body publisher is not producing data, "
54+
+ "for example when using AsyncRequestBody.fromInputStream() with an "
55+
+ "executor that has fewer threads than concurrent requests. "
56+
+ "Verify that the request body publisher is sending data or "
57+
+ "investigate why it may be blocked.", timeoutMillis);
58+
ctx.fireExceptionCaught(new IOException(errorMessageWithChannelDiagnostics(ctx.channel(), message)));
6059
ctx.close();
6160
closed = true;
6261
}

http-clients/netty-nio-client/src/test/java/software/amazon/awssdk/http/nio/netty/fault/WriteIdleTimeoutTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void stalledBodyPublisher_shouldTriggerWriteIdleTimeout() throws Interrup
106106

107107
assertThatThrownBy(() -> future.get(5, TimeUnit.SECONDS))
108108
.hasCauseInstanceOf(IOException.class)
109-
.hasStackTraceContaining("No data was written to the request body");
109+
.hasStackTraceContaining("No data was written to the request body within 500ms");
110110
}
111111

112112
private CompletableFuture<Void> sendRequest(SdkHttpFullRequest request, SdkHttpContentPublisher contentPublisher) {

http-clients/netty-nio-client/src/test/java/software/amazon/awssdk/http/nio/netty/internal/HandlerRemovingChannelPoolListenerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void setup() throws Exception {
7474
pipeline.addLast(new ReadTimeoutHandler(10));
7575
pipeline.addLast(new WriteTimeoutHandler(10));
7676
pipeline.addLast(new IdleStateHandler(0, 10, 0));
77-
pipeline.addLast(new WriteIdleTimeoutHandler());
77+
pipeline.addLast(new WriteIdleTimeoutHandler(10000));
7878
handler = HandlerRemovingChannelPoolListener.create();
7979
}
8080

http-clients/netty-nio-client/src/test/java/software/amazon/awssdk/http/nio/netty/internal/WriteIdleTimeoutHandlerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ class WriteIdleTimeoutHandlerTest {
2828

2929
@Test
3030
void writerIdleEvent_shouldFireExceptionAndCloseChannel() {
31-
EmbeddedChannel channel = new EmbeddedChannel(new WriteIdleTimeoutHandler());
31+
EmbeddedChannel channel = new EmbeddedChannel(new WriteIdleTimeoutHandler(30000));
3232

3333
channel.pipeline().fireUserEventTriggered(IdleStateEvent.WRITER_IDLE_STATE_EVENT);
3434

3535
assertThat(channel.isOpen()).isFalse();
3636
assertThatThrownBy(channel::checkException)
3737
.isInstanceOf(IOException.class)
38-
.hasMessageContaining("No data was written to the request body");
38+
.hasMessageContaining("No data was written to the request body within 30000ms");
3939
}
4040

4141
@Test
4242
void readerIdleEvent_shouldBeIgnored() {
43-
EmbeddedChannel channel = new EmbeddedChannel(new WriteIdleTimeoutHandler());
43+
EmbeddedChannel channel = new EmbeddedChannel(new WriteIdleTimeoutHandler(30000));
4444

4545
channel.pipeline().fireUserEventTriggered(IdleStateEvent.READER_IDLE_STATE_EVENT);
4646

@@ -49,7 +49,7 @@ void readerIdleEvent_shouldBeIgnored() {
4949

5050
@Test
5151
void duplicateWriterIdleEvent_shouldNotFireTwice() {
52-
EmbeddedChannel channel = new EmbeddedChannel(new WriteIdleTimeoutHandler());
52+
EmbeddedChannel channel = new EmbeddedChannel(new WriteIdleTimeoutHandler(30000));
5353

5454
channel.pipeline().fireUserEventTriggered(IdleStateEvent.WRITER_IDLE_STATE_EVENT);
5555

0 commit comments

Comments
 (0)