Skip to content

Commit 37bd3fd

Browse files
authored
Merge branch 'master' into remove-medialive
2 parents f22a72e + c9fd7c0 commit 37bd3fd

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"contributor": "",
4+
"type": "bugfix",
5+
"description": "Fix leak of bytebuf on HTTP GoAway"
6+
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
package software.amazon.awssdk.http.nio.netty.internal.http2;
1717

18-
import io.netty.buffer.ByteBuf;
1918
import java.io.IOException;
20-
import java.nio.charset.StandardCharsets;
2119
import software.amazon.awssdk.annotations.SdkInternalApi;
2220

2321
/**
@@ -27,10 +25,10 @@
2725
public class GoAwayException extends IOException {
2826
private final String message;
2927

30-
GoAwayException(long errorCode, ByteBuf debugData) {
28+
GoAwayException(long errorCode, String debugData) {
3129
this.message = String.format("GOAWAY received from service, requesting this stream be closed. "
3230
+ "Error Code = %d, Debug Data = %s",
33-
errorCode, debugData.toString(StandardCharsets.UTF_8));
31+
errorCode, debugData);
3432
}
3533

3634
@Override

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.netty.channel.Channel;
2020
import io.netty.handler.codec.http2.Http2ConnectionAdapter;
2121
import io.netty.handler.codec.http2.Http2GoAwayFrame;
22+
import java.nio.charset.StandardCharsets;
2223
import software.amazon.awssdk.annotations.SdkInternalApi;
2324
import software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey;
2425
import software.amazon.awssdk.utils.Logger;
@@ -41,7 +42,7 @@ public Http2GoAwayEventListener(Channel parentChannel) {
4142
@Override
4243
public void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData) {
4344
Http2MultiplexedChannelPool channelPool = parentChannel.attr(ChannelAttributeKey.HTTP2_MULTIPLEXED_CHANNEL_POOL).get();
44-
GoAwayException exception = new GoAwayException(errorCode, debugData.retain());
45+
GoAwayException exception = new GoAwayException(errorCode, debugData.toString(StandardCharsets.UTF_8));
4546
if (channelPool != null) {
4647
channelPool.handleGoAway(parentChannel, lastStreamId, exception);
4748
} else {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515

1616
package software.amazon.awssdk.http.nio.netty.internal.http2;
1717

18+
import static org.junit.Assert.assertEquals;
1819
import static org.mockito.Matchers.eq;
1920
import static org.mockito.Matchers.isA;
2021
import static org.mockito.Mockito.mock;
2122
import static org.mockito.Mockito.verify;
2223
import static org.mockito.Mockito.verifyNoMoreInteractions;
2324
import static org.mockito.Mockito.when;
2425

26+
import io.netty.buffer.ByteBuf;
2527
import io.netty.buffer.Unpooled;
2628
import io.netty.channel.Channel;
2729
import io.netty.channel.ChannelHandlerContext;
@@ -53,16 +55,20 @@ public void setup() {
5355
@Test
5456
public void goAwayWithNoChannelPoolRecordRaisesNoExceptions() throws Exception {
5557
when(attribute.get()).thenReturn(null);
56-
new Http2GoAwayEventListener(channel).onGoAwayReceived(0, 0, Unpooled.EMPTY_BUFFER);
58+
ByteBuf emptyBuffer = Unpooled.EMPTY_BUFFER;
59+
new Http2GoAwayEventListener(channel).onGoAwayReceived(0, 0, emptyBuffer);
5760
verify(channelPipeline).fireExceptionCaught(isA(GoAwayException.class));
61+
assertEquals(1, emptyBuffer.refCnt());
5862
}
5963

6064
@Test
6165
public void goAwayWithChannelPoolRecordPassesAlongTheFrame() throws Exception {
6266
Http2MultiplexedChannelPool record = mock(Http2MultiplexedChannelPool.class);
6367
when(attribute.get()).thenReturn(record);
64-
new Http2GoAwayEventListener(channel).onGoAwayReceived(0, 0, Unpooled.EMPTY_BUFFER);
68+
ByteBuf emptyBuffer = Unpooled.EMPTY_BUFFER;
69+
new Http2GoAwayEventListener(channel).onGoAwayReceived(0, 0, emptyBuffer);
6570
verify(record).handleGoAway(eq(channel), eq(0), isA(GoAwayException.class));
6671
verifyNoMoreInteractions(record);
72+
assertEquals(1, emptyBuffer.refCnt());
6773
}
6874
}

0 commit comments

Comments
 (0)