GeezerVison is showing github.com — InboundHttp2ToHttpAdapter maxContentLength exceeded causes connection error · Issue #11994 · netty/netty
InboundHttp2ToHttpAdapter maxContentLength exceeded causes connection error #11994DescriptionExpected behavior
When using InboundHttp2ToHttpAdapter, sending a payload that exceeds maxContentLength should return a status code of 413 before closing the stream.
Actual behavior
If a message payload exceeds maxContentLength, a connection error is thrown causing a GO_AWAY to be sent. This is confusing behavior to clients and we have seen load balancers treat these errors as 5xx errors when it's expected to be a client (4xx) error.
|
if (content.readableBytes() > maxContentLength - dataReadableBytes) { |
|
throw connectionError(INTERNAL_ERROR, |
|
"Content length exceeded max of %d for stream id %d", maxContentLength, streamId); |
|
} |
|
protected void onConnectionError(ChannelHandlerContext ctx, boolean outbound, |
|
Throwable cause, Http2Exception http2Ex) { |
|
if (http2Ex == null) { |
|
http2Ex = new Http2Exception(INTERNAL_ERROR, cause.getMessage(), cause); |
|
} |
|
|
|
ChannelPromise promise = ctx.newPromise(); |
|
ChannelFuture future = goAway(ctx, http2Ex, ctx.newPromise()); |
|
if (http2Ex.shutdownHint() == Http2Exception.ShutdownHint.GRACEFUL_SHUTDOWN) { |
|
doGracefulShutdown(ctx, future, promise); |
|
} else { |
|
future.addListener(newClosingChannelFutureListener(ctx, promise)); |
|
} |
|
} |
Curious if there's something I'm missing about why this results in a connection error.
Steps to reproduce
Send a payload exceeding maxContentLength configured here to a pipeline using InboundHttp2ToHttpAdapter:
|
@Override |
|
public InboundHttp2ToHttpAdapterBuilder maxContentLength(int maxContentLength) { |
|
return super.maxContentLength(maxContentLength); |
|
} |
Netty version
4.1.73.Final Activitynormanmaurer commented on Jan 13, 2022 BrianRothermich commented on Jan 13, 2022 @normanmaurer I'm primarily just suggesting that a 413 status code should be returned for this case. It does seem like this would fall under a stream error, though. wanglunhui2012 commented on Jan 13, 2022 normanmaurer commented on Jan 13, 2022 BrianRothermich commented on Jan 14, 2022
maybe ENHANCE_YOUR_CALM would be better ?
sgtm. I'm happy to provide a PR. normanmaurer commented on Jan 14, 2022 added 2 commits that reference this issue on Mar 26, 2026This issue will close once commit 3f0b146 is merged into the '4.1' branch.3f0b146 This issue will close once commit 0a5d42e is merged into the '4.1' branch.0a5d42e added a commit that references this issue on Apr 10, 2026This issue will close once commit d8dd805 is merged into the '4.2' branch.d8dd805 added 2 commits that reference this issue on Apr 10, 2026This issue will close once commit 63edd7b is merged into the '4.2' branch.63edd7b This issue will close once commit e1df9cc is merged into the '4.2' branch.e1df9cc added 2 commits that reference this issue on Apr 11, 2026This issue will close once commit 8f51ad3 is merged into the '4.1' branch.8f51ad3 This issue will close once commit 5aa5d72 is merged into the '4.2' branch.5aa5d72
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|