GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Avoid classloader leak via the QPACK stream inactive exceptions · netty/netty@ea9b287

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http3/src
    • main/java/io/netty/handler/codec/http3
      • Http3ControlStreamInboundHandler.java
    • test/java/io/netty/handler/codec/http3
      • Http3ControlStreamInboundHandlerTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http3/src/main/java/io/netty/handler/codec/http3/Http3ControlStreamInboundHandler.java‎

Copy file name to clipboardExpand all lines: codec-http3/src/main/java/io/netty/handler/codec/http3/Http3ControlStreamInboundHandler.java
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.netty.channel.ChannelHandler;
2020
import io.netty.channel.ChannelHandlerContext;
2121
import io.netty.channel.ChannelInboundHandlerAdapter;
22+
import io.netty.channel.StacklessClosedChannelException;
2223
import io.netty.channel.socket.ChannelInputShutdownEvent;
2324
import io.netty.handler.codec.quic.QuicChannel;
2425
import io.netty.handler.codec.quic.QuicStreamChannel;
@@ -38,9 +39,15 @@
3839
import static io.netty.handler.codec.http3.Http3ErrorCode.H3_MISSING_SETTINGS;
3940
import static io.netty.handler.codec.http3.Http3ErrorCode.QPACK_ENCODER_STREAM_ERROR;
4041
import static io.netty.handler.codec.http3.QpackUtil.toIntOrThrow;
41-
import static io.netty.util.internal.ThrowableUtil.unknownStackTrace;
4242

4343
final class Http3ControlStreamInboundHandler extends Http3FrameTypeInboundValidationHandler<Http3ControlStreamFrame> {
44+
// Stackless, as a populated backtrace would pin the Classloader of whatever thread happened to trigger the
45+
// class initialization (see https://github.com/netty/netty/issues/17128).
46+
static final ClosedChannelException ENCODER_STREAM_INACTIVE =
47+
StacklessClosedChannelException.newInstance(QPackEncoderStreamInitializer.class, "streamClosed()");
48+
static final ClosedChannelException DECODER_STREAM_INACTIVE =
49+
StacklessClosedChannelException.newInstance(QPackDecoderStreamInitializer.class, "streamClosed()");
50+
4451
final boolean server;
4552
private final ChannelHandler controlFrameHandler;
4653
private final QpackEncoder qpackEncoder;
@@ -278,8 +285,6 @@ public void channelInactive(ChannelHandlerContext ctx) {
278285
}
279286

280287
private static final class QPackEncoderStreamInitializer extends AbstractQPackStreamInitializer {
281-
private static final ClosedChannelException ENCODER_STREAM_INACTIVE =
282-
unknownStackTrace(new ClosedChannelException(), ClosedChannelException.class, "streamClosed()");
283288
private final QpackEncoder encoder;
284289
private final long maxTableCapacity;
285290
private final long blockedStreams;
@@ -312,8 +317,6 @@ protected void streamClosed(ChannelHandlerContext ctx) {
312317
}
313318

314319
private static final class QPackDecoderStreamInitializer extends AbstractQPackStreamInitializer {
315-
private static final ClosedChannelException DECODER_STREAM_INACTIVE =
316-
unknownStackTrace(new ClosedChannelException(), ClosedChannelException.class, "streamClosed()");
317320
private QPackDecoderStreamInitializer(QpackAttributes attributes) {
318321
super(Http3CodecUtils.HTTP3_QPACK_DECODER_STREAM_TYPE, attributes);
319322
}
Collapse file

‎codec-http3/src/test/java/io/netty/handler/codec/http3/Http3ControlStreamInboundHandlerTest.java‎

Copy file name to clipboardExpand all lines: codec-http3/src/test/java/io/netty/handler/codec/http3/Http3ControlStreamInboundHandlerTest.java
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
import io.netty.channel.embedded.EmbeddedChannel;
2121
import io.netty.handler.codec.quic.QuicStreamType;
2222
import io.netty.util.ReferenceCountUtil;
23+
import org.junit.jupiter.api.Test;
2324
import org.junit.jupiter.params.ParameterizedTest;
2425
import org.junit.jupiter.params.provider.MethodSource;
2526
import org.junit.jupiter.params.provider.ValueSource;
2627

28+
import java.nio.channels.ClosedChannelException;
2729
import java.util.ArrayList;
2830
import java.util.Arrays;
2931
import java.util.Collection;
@@ -33,6 +35,7 @@
3335
import static io.netty.handler.codec.http3.Http3TestUtils.assertFrameReleased;
3436
import static io.netty.handler.codec.http3.Http3TestUtils.assertFrameSame;
3537
import static io.netty.handler.codec.http3.Http3TestUtils.verifyClose;
38+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
3639
import static org.junit.jupiter.api.Assertions.assertEquals;
3740
import static org.junit.jupiter.api.Assertions.assertFalse;
3841
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -48,6 +51,25 @@ public Http3ControlStreamInboundHandlerTest() {
4851
super(QuicStreamType.UNIDIRECTIONAL, false, false);
4952
}
5053

54+
@Test
55+
public void testStreamInactiveFailuresDoNotFillInStackTrace() {
56+
// These are static, so they must not populate a (native) backtrace: doing so would pin the Classloader of
57+
// whatever thread happened to trigger the class initialization
58+
// (see https://github.com/netty/netty/issues/17128).
59+
assertNoStackTrace(Http3ControlStreamInboundHandler.ENCODER_STREAM_INACTIVE);
60+
assertNoStackTrace(Http3ControlStreamInboundHandler.DECODER_STREAM_INACTIVE);
61+
}
62+
63+
private static void assertNoStackTrace(ClosedChannelException cause) {
64+
StackTraceElement[] before = cause.getStackTrace();
65+
assertEquals(1, before.length);
66+
assertEquals("streamClosed()", before[0].getMethodName());
67+
68+
// fillInStackTrace() must be a no-op; otherwise it would repopulate the backtrace with native frames.
69+
cause.fillInStackTrace();
70+
assertArrayEquals(before, cause.getStackTrace());
71+
}
72+
5173
static Collection<Object[]> testData() {
5274
List<Object[]> config = new ArrayList<>();
5375
for (int a = 0; a < 2; a++) {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.