@@ -289,6 +289,74 @@ public void run() throws Http2Exception { |
289 | 289 | } |
290 | 290 | } |
291 | 291 |
|
| 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 | + |
292 | 360 | @Test |
293 | 361 | public void clientRequestMultipleDataFrames() throws Exception { |
294 | 362 | boostrapEnv(1, 1, 1); |
|