Expected 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
Expected 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.
netty/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java
Lines 237 to 240 in c6e65cc
netty/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java
Lines 665 to 678 in c6e65cc
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:netty/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapterBuilder.java
Lines 36 to 39 in c6e65cc
Netty version
4.1.73.Final