Skip to content

Commit

Permalink
netty: fix status message when GOAWAY at MAX_CONCURRENT_STREAMS limit
Browse files Browse the repository at this point in the history
Resolves #8097
  • Loading branch information
dapengzhang0 committed Apr 22, 2021
1 parent b66d8b6 commit 332a2d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
22 changes: 14 additions & 8 deletions netty/src/main/java/io/grpc/netty/NettyClientHandler.java
Expand Up @@ -563,17 +563,23 @@ private void createStream(CreateStreamCommand command, ChannelPromise promise)
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;
Expand Down
Expand Up @@ -378,7 +378,7 @@ public void receivedAbruptGoAwayShouldFailRacingQueuedStreamid() throws Exceptio
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());
}
Expand Down Expand Up @@ -411,6 +411,8 @@ public void receivedGoAway_shouldFailBufferedStreamsExceedingMaxConcurrentStream
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
Expand Down

0 comments on commit 332a2d8

Please sign in to comment.