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 — Use stream error for maxContentLength exceeded in InboundHttp2ToHttpA… · netty/netty@63edd7b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http2/src
    • main/java/io/netty/handler/codec/http2
      • InboundHttp2ToHttpAdapter.java
    • test/java/io/netty/handler/codec/http2
      • InboundHttp2ToHttpAdapterTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java‎

Copy file name to clipboardExpand all lines: codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
import io.netty.handler.codec.http.HttpStatusClass;
2525
import io.netty.handler.codec.http.HttpUtil;
2626

27-
import static io.netty.handler.codec.http2.Http2Error.INTERNAL_ERROR;
27+
import static io.netty.handler.codec.http2.Http2Error.ENHANCE_YOUR_CALM;
2828
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
2929
import static io.netty.handler.codec.http2.Http2Exception.connectionError;
30+
import static io.netty.handler.codec.http2.Http2Exception.streamError;
3031
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
3132
import static io.netty.util.internal.ObjectUtil.checkNotNull;
3233
import static io.netty.util.internal.ObjectUtil.checkPositive;
@@ -233,7 +234,7 @@ public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int
233234
ByteBuf content = msg.content();
234235
final int dataReadableBytes = data.readableBytes();
235236
if (content.readableBytes() > maxContentLength - dataReadableBytes) {
236-
throw connectionError(INTERNAL_ERROR,
237+
throw streamError(streamId, ENHANCE_YOUR_CALM,
237238
"Content length exceeded max of %d for stream id %d", maxContentLength, streamId);
238239
}
239240

Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapterTest.java‎

Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapterTest.java
+68Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,74 @@ public void run() throws Http2Exception {
289289
}
290290
}
291291

292+
@Test
293+
public void exceedMaxContentLengthShouldCauseStreamErrorNotConnectionError() throws Exception {
294+
// Verify that exceeding maxContentLength causes a stream error (RST_STREAM)
295+
// not a connection error (GOAWAY), so other streams can continue.
296+
// This is the fix for https://github.com/netty/netty/issues/11994
297+
//
298+
// clientLatch=1: RST_STREAM for stream 3 triggers onRstStreamRead on the client,
299+
// which fires exceptionCaught and counts down clientLatch.
300+
// With a connection error (GOAWAY), no RST_STREAM is sent, so clientLatch
301+
// never counts down and awaitResponses() times out — failing the test.
302+
// serverLatch=1: stream 5 request should be delivered normally.
303+
boostrapEnv(1, 1, 1);
304+
final byte[] oversizedData = new byte[maxContentLength + 1];
305+
final ByteBuf oversizedContent = Unpooled.wrappedBuffer(oversizedData);
306+
final String normalText = "hello";
307+
final ByteBuf normalContent = Unpooled.copiedBuffer(normalText.getBytes());
308+
final FullHttpRequest expectedRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
309+
"/normal/path", normalContent.copy(), true);
310+
try {
311+
HttpHeaders httpHeaders = expectedRequest.headers();
312+
httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
313+
httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, normalText.length());
314+
httpHeaders.setShort(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), (short) 16);
315+
final Http2Headers oversizedHeaders = new DefaultHttp2Headers().method(new AsciiString("POST")).path(
316+
new AsciiString("/oversized/path"));
317+
final Http2Headers normalHeaders = new DefaultHttp2Headers().method(new AsciiString("GET")).path(
318+
new AsciiString("/normal/path"));
319+
runInChannel(clientChannel, new Http2Runnable() {
320+
@Override
321+
public void run() throws Http2Exception {
322+
// Stream 3: send data exceeding maxContentLength - should cause stream error
323+
clientHandler.encoder().writeHeaders(ctxClient(), 3, oversizedHeaders, 0, false,
324+
newPromiseClient());
325+
clientHandler.encoder().writeData(ctxClient(), 3, oversizedContent, 0, true,
326+
newPromiseClient());
327+
// Stream 5: send a normal request - should succeed if connection is still alive
328+
clientHandler.encoder().writeHeaders(ctxClient(), 5, normalHeaders, 0, false,
329+
newPromiseClient());
330+
clientHandler.encoder().writeData(ctxClient(), 5, normalContent, 0, true,
331+
newPromiseClient());
332+
clientChannel.flush();
333+
}
334+
});
335+
336+
// Verify stream 5 is delivered successfully on the server
337+
awaitRequests();
338+
ArgumentCaptor<FullHttpMessage> requestCaptor = ArgumentCaptor.forClass(FullHttpMessage.class);
339+
verify(serverListener).messageReceived(requestCaptor.capture());
340+
capturedRequests = requestCaptor.getAllValues();
341+
assertEquals(expectedRequest, capturedRequests.get(0));
342+
343+
// Verify the client received RST_STREAM (not GOAWAY) for the oversized stream.
344+
// The server's onStreamError sends RST_STREAM, which the client's
345+
// InboundHttp2ToHttpAdapter.onRstStreamRead translates into an exceptionCaught
346+
// event carrying a StreamException — this counts down clientLatch.
347+
// With a connection error, the server sends GOAWAY instead — no RST_STREAM is
348+
// received, exceptionCaught never fires, and awaitResponses() times out.
349+
awaitResponses();
350+
assertNotNull(clientException);
351+
assertTrue(isStreamError(clientException));
352+
Http2Exception.StreamException streamEx = (Http2Exception.StreamException) clientException;
353+
assertEquals(3, streamEx.streamId());
354+
assertEquals(Http2Error.ENHANCE_YOUR_CALM, streamEx.error());
355+
} finally {
356+
expectedRequest.release();
357+
}
358+
}
359+
292360
@Test
293361
public void clientRequestMultipleDataFrames() throws Exception {
294362
boostrapEnv(1, 1, 1);

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.