From eb6764841b1771e64d222430de7a12c9a6b4ead7 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Fri, 16 Apr 2021 16:10:38 -0700 Subject: [PATCH] netty: fix status message when GOAWAY at MAX_CONCURRENT_STREAMS limit Resolves #8097 --- .../io/grpc/netty/NettyClientHandler.java | 22 ++++++++++++------- .../io/grpc/netty/NettyClientHandlerTest.java | 4 +++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/netty/src/main/java/io/grpc/netty/NettyClientHandler.java b/netty/src/main/java/io/grpc/netty/NettyClientHandler.java index 393b364496..d263356204 100644 --- a/netty/src/main/java/io/grpc/netty/NettyClientHandler.java +++ b/netty/src/main/java/io/grpc/netty/NettyClientHandler.java @@ -570,17 +570,23 @@ class NettyClientHandler extends AbstractNettyHandler { return; } if (connection().goAwayReceived()) { - if (streamId > connection().local().lastStreamKnownByPeer() - || connection().local().numActiveStreams() == connection().local().maxActiveStreams()) { + Status s = abruptGoAwayStatus; + int maxActiveStreams = connection().local().maxActiveStreams(); + int lastStreamId = connection().local().lastStreamKnownByPeer(); + if (s == null) { + // Should be impossible, but handle pseudo-gracefully + s = Status.INTERNAL.withDescription( + "Failed due to abrupt GOAWAY, but can't find GOAWAY details"); + } else if (streamId > lastStreamId) { + s = s.augmentDescription( + "stream id: " + streamId + ", GOAWAY Last-Stream-ID:" + lastStreamId); + } else if (connection().local().numActiveStreams() == maxActiveStreams) { + s = s.augmentDescription("At MAX_CONCURRENT_STREAMS limit. limit: " + maxActiveStreams); + } + if (streamId > lastStreamId || connection().local().numActiveStreams() == maxActiveStreams) { // This should only be reachable during onGoAwayReceived, as otherwise // getShutdownThrowable() != null command.stream().setNonExistent(); - Status s = abruptGoAwayStatus; - if (s == null) { - // Should be impossible, but handle psuedo-gracefully - s = Status.INTERNAL.withDescription( - "Failed due to abrupt GOAWAY, but can't find GOAWAY details"); - } command.stream().transportReportStatus(s, RpcProgress.REFUSED, true, new Metadata()); promise.setFailure(s.asRuntimeException()); return; diff --git a/netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java b/netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java index b901ceeb64..d105bcd28d 100644 --- a/netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java @@ -378,7 +378,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase