diff --git a/netty/src/main/java/io/grpc/netty/StreamBufferingEncoder.java b/netty/src/main/java/io/grpc/netty/StreamBufferingEncoder.java index 17f56370e5f..bac0049de41 100644 --- a/netty/src/main/java/io/grpc/netty/StreamBufferingEncoder.java +++ b/netty/src/main/java/io/grpc/netty/StreamBufferingEncoder.java @@ -42,9 +42,29 @@ import java.util.TreeMap; /** - * This is a temporary copy of {@link io.netty.handler.codec.http2.DecoratingHttp2ConnectionEncoder} - * with a bug fix that is not available yet in the latest netty release. + * Implementation of a {@link Http2ConnectionEncoder} that dispatches all method call to another + * {@link Http2ConnectionEncoder}, until {@code SETTINGS_MAX_CONCURRENT_STREAMS} is reached. + *

+ *

When this limit is hit, instead of rejecting any new streams this implementation buffers newly + * created streams and their corresponding frames. Once an active stream gets closed or the maximum + * number of concurrent streams is increased, this encoder will automatically try to empty its + * buffer and create as many new streams as possible. + *

+ *

+ * If a {@code GOAWAY} frame is received from the remote endpoint, all buffered writes for streams + * with an ID less than the specified {@code lastStreamId} will immediately fail with a + * {@link io.netty.handler.codec.http2.StreamBufferingEncoder.Http2GoAwayException}. + *

+ *

+ * If the channel/encoder gets closed, all new and buffered writes will immediately fail with a + * {@link io.netty.handler.codec.http2.StreamBufferingEncoder.Http2ChannelClosedException}. + *

+ *

This implementation makes the buffering mostly transparent and is expected to be used as a + * drop-in decorator of {@link io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder}. + *

*/ +// This is a temporary copy of {@link io.netty.handler.codec.http2.DecoratingHttp2ConnectionEncoder} +// with a bug fix that is not available yet in the latest netty release. class StreamBufferingEncoder extends DecoratingHttp2ConnectionEncoder { /** @@ -138,11 +158,7 @@ public ChannelFuture writeHeaders(ChannelHandlerContext ctx, int streamId, Http2 if (closed) { return promise.setFailure(new Http2ChannelClosedException()); } - if (isExistingStream(streamId) || connection().goAwayReceived()) { - return super.writeHeaders(ctx, streamId, headers, streamDependency, weight, - exclusive, padding, endOfStream, promise); - } - if (canCreateStream()) { + if (isExistingStream(streamId) || canCreateStream()) { return super.writeHeaders(ctx, streamId, headers, streamDependency, weight, exclusive, padding, endOfStream, promise); }