netty: fix status message when GOAWAY at MAX_CONCURRENT_STREAMS limit

Resolves #8097
This commit is contained in:
ZHANG Dapeng 2021-04-16 16:10:38 -07:00 committed by GitHub
parent 49f9380fc9
commit eb6764841b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 9 deletions

View File

@ -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;

View File

@ -378,7 +378,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase<NettyClientHand
assertEquals(Status.UNAVAILABLE.getCode(), captor.getValue().getCode());
assertEquals(
"Abrupt GOAWAY closed unsent stream. HTTP/2 error code: CANCEL, "
+ "debug data: this is a test",
+ "debug data: this is a test\nstream id: 3, GOAWAY Last-Stream-ID:0",
captor.getValue().getDescription());
assertTrue(future.isDone());
}
@ -411,6 +411,8 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase<NettyClientHand
assertThat(Status.fromThrowable(future2.cause()).getCode()).isEqualTo(Status.Code.UNAVAILABLE);
assertThat(future2.cause().getMessage()).contains(
"Abrupt GOAWAY closed unsent stream. HTTP/2 error code: NO_ERROR");
assertThat(future2.cause().getMessage()).contains(
"At MAX_CONCURRENT_STREAMS limit");
}
@Test