From 8840f0a8e599ba6208eaf519bad9261f7cd82faf Mon Sep 17 00:00:00 2001 From: Idel Pivnitskiy Date: Wed, 1 Sep 2021 16:17:06 -0700 Subject: [PATCH 1/2] Include number of maximum active streams in exception message Motivation: When users receive "Maximum active streams violated for this endpoint" exception, it's useful to know what is the current max streams limit on HTTP/2 connection. Modifications: - Include current number of maximum active streams in exception message; Result: Easier debugging of HTTP/2 connections. --- .../handler/codec/http2/DefaultHttp2Connection.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java index 5c622d6f735..5750e062301 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java @@ -483,8 +483,10 @@ public final V removeProperty(PropertyKey key) { @Override public Http2Stream open(boolean halfClosed) throws Http2Exception { state = activeState(id, state, isLocal(), halfClosed); - if (!createdBy().canOpenStream()) { - throw connectionError(PROTOCOL_ERROR, "Maximum active streams violated for this endpoint."); + final DefaultEndpoint endpoint = createdBy(); + if (!endpoint.canOpenStream()) { + throw connectionError(PROTOCOL_ERROR, "Maximum active streams violated for this endpoint: " + + endpoint.maxActiveStreams()); } activate(); @@ -896,8 +898,9 @@ private void checkNewStreamAllowed(int streamId, State state) throws Http2Except Http2Exception.ShutdownHint.GRACEFUL_SHUTDOWN); } boolean isReserved = state == RESERVED_LOCAL || state == RESERVED_REMOTE; - if (!isReserved && !canOpenStream() || isReserved && numStreams >= maxStreams) { - throw streamError(streamId, REFUSED_STREAM, "Maximum active streams violated for this endpoint."); + if (isReserved ? numStreams >= maxStreams : !canOpenStream()) { + throw streamError(streamId, REFUSED_STREAM, "Maximum active streams violated for this endpoint: " + + (isReserved ? maxStreams : maxActiveStreams)); } if (isClosed()) { throw connectionError(INTERNAL_ERROR, "Attempted to create stream id %d after connection was closed", From 92b67cb2427a353a3cab318f94d29953c374724c Mon Sep 17 00:00:00 2001 From: Idel Pivnitskiy Date: Thu, 2 Sep 2021 11:28:07 -0700 Subject: [PATCH 2/2] revert conditional --- .../io/netty/handler/codec/http2/DefaultHttp2Connection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java index 5750e062301..dd9680e6533 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java @@ -898,7 +898,7 @@ private void checkNewStreamAllowed(int streamId, State state) throws Http2Except Http2Exception.ShutdownHint.GRACEFUL_SHUTDOWN); } boolean isReserved = state == RESERVED_LOCAL || state == RESERVED_REMOTE; - if (isReserved ? numStreams >= maxStreams : !canOpenStream()) { + if (!isReserved && !canOpenStream() || isReserved && numStreams >= maxStreams) { throw streamError(streamId, REFUSED_STREAM, "Maximum active streams violated for this endpoint: " + (isReserved ? maxStreams : maxActiveStreams)); }