diff --git a/alts/src/main/java/io/grpc/alts/internal/ProtectedPromise.java b/alts/src/main/java/io/grpc/alts/internal/ProtectedPromise.java index a19a8160f5..e204acdd5f 100644 --- a/alts/src/main/java/io/grpc/alts/internal/ProtectedPromise.java +++ b/alts/src/main/java/io/grpc/alts/internal/ProtectedPromise.java @@ -18,6 +18,7 @@ package io.grpc.alts.internal; import static com.google.common.base.Preconditions.checkState; +import io.grpc.Internal; import io.netty.channel.Channel; import io.netty.channel.ChannelPromise; import io.netty.channel.DefaultChannelPromise; @@ -34,14 +35,15 @@ import java.util.List; * *
NOTE: this code is based on code in Netty's {@code Http2CodecUtil}.
*/
-final class ProtectedPromise extends DefaultChannelPromise {
+@Internal
+public final class ProtectedPromise extends DefaultChannelPromise {
private final List Internal use only. Do not use.
+ */
+ public static void writeBufferingAndRemove(Channel channel) {
+ NettyClientHandler.writeBufferingAndRemove(channel);
+ }
+}
diff --git a/netty/src/main/java/io/grpc/netty/NettyClientHandler.java b/netty/src/main/java/io/grpc/netty/NettyClientHandler.java
index 90890dff9d..5cf74d8efd 100644
--- a/netty/src/main/java/io/grpc/netty/NettyClientHandler.java
+++ b/netty/src/main/java/io/grpc/netty/NettyClientHandler.java
@@ -18,6 +18,7 @@ package io.grpc.netty;
import static io.netty.handler.codec.http2.DefaultHttp2LocalFlowController.DEFAULT_WINDOW_UPDATE_RATIO;
import static io.netty.util.CharsetUtil.UTF_8;
+import static io.netty.util.internal.ObjectUtil.checkNotNull;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
@@ -445,12 +446,17 @@ class NettyClientHandler extends AbstractNettyHandler {
this.attributes = this.attributes.toBuilder().setAll(attributes).build();
this.securityInfo = securityInfo;
super.handleProtocolNegotiationCompleted(attributes, securityInfo);
- // Once protocol negotiator is complete, release all writes and remove the buffer.
+ writeBufferingAndRemove(ctx().channel());
+ }
+
+ static void writeBufferingAndRemove(Channel channel) {
+ checkNotNull(channel, "channel");
ChannelHandlerContext handlerCtx =
- ctx().pipeline().context(WriteBufferingAndExceptionHandler.class);
- if (handlerCtx != null) {
- ((WriteBufferingAndExceptionHandler) handlerCtx.handler()).writeBufferedAndRemove(handlerCtx);
+ channel.pipeline().context(WriteBufferingAndExceptionHandler.class);
+ if (handlerCtx == null) {
+ return;
}
+ ((WriteBufferingAndExceptionHandler) handlerCtx.handler()).writeBufferedAndRemove(handlerCtx);
}
@Override