Skip to content

InboundHttp2ToHttpAdapter maxContentLength exceeded causes connection error #11994

@BrianRothermich

Description

@BrianRothermich

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions