Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit 6113c9f

Browse files
authored
Ensure buffer is released even if future fails (#320)
Motivation: We should release in a finally blog so we don't leak on failure Modifications: Move release() to finally block. Result: No more leaks when write fails
1 parent 2c70568 commit 6113c9f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/test/java/io/netty/incubator/codec/quic/QuicReadableTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public boolean isSharable() {
8282
});
8383
Channel channel = QuicTestUtils.newClient();
8484
QuicChannelValidationHandler clientHandler = new QuicChannelValidationHandler();
85+
ByteBuf data = Unpooled.directBuffer().writeLong(8);
8586
try {
8687
QuicChannel quicChannel = QuicChannel.newBootstrap(channel)
8788
.handler(clientHandler)
@@ -90,7 +91,6 @@ public boolean isSharable() {
9091
.connect()
9192
.get();
9293

93-
ByteBuf data = Unpooled.directBuffer().writeLong(8);
9494
List<Channel> streams = new ArrayList<>();
9595
for (int i = 0; i < numOfStreams; i++) {
9696
QuicStreamChannel stream = quicChannel.createStream(
@@ -102,7 +102,6 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
102102
}).get();
103103
streams.add(stream.writeAndFlush(data.retainedSlice()).sync().channel());
104104
}
105-
data.release();
106105
latch.await();
107106
while (bytesRead.get() < expectedDataRead) {
108107
Thread.sleep(50);
@@ -118,6 +117,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
118117
serverHandler.assertState();
119118
clientHandler.assertState();
120119
} finally {
120+
data.release();
121121
server.close().sync();
122122
// Close the parent Datagram channel as well.
123123
channel.close().sync();

0 commit comments

Comments
 (0)