Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public void notifyGracefulShutdown(Status s, DisconnectError disconnectError) {
public boolean notifyShutdown(Status s, DisconnectError disconnectError) {
notifyGracefulShutdown(s, disconnectError);
if (shutdownStatus != null) {
// Check if the incoming error is just the routine channel closure exception
boolean isClosedChannel = s.getCause() instanceof java.nio.channels.ClosedChannelException;

// Status Upgrade: Overwrite graceful shutdown if a hard network error occurs
if (shutdownStatus.getCause() == null && s.getCause() != null && !isClosedChannel) {
shutdownStatus = s;
return true;
}
return false;
}
shutdownStatus = s;
Expand Down
25 changes: 25 additions & 0 deletions netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,31 @@ public void maxMessageSizeShouldBeEnforced() throws Throwable {
}
}

@Test
public void networkErrorOverridesGracefulShutdownStatus() throws Exception {
startServer();
NettyClientTransport transport = newTransport(newNegotiator());
callMeMaybe(transport.start(clientTransportListener));

// 1. Trigger graceful shutdown
Status gracefulStatus = Status.UNAVAILABLE.withDescription("Channel shutdown invoked");
transport.shutdown(gracefulStatus);

// 2. Simulate a real network drop (e.g., Connection Reset)
java.io.IOException networkCause = new java.io.IOException("Connection reset by peer");
transport.channel().pipeline().fireExceptionCaught(networkCause);
transport.channel().pipeline().fireChannelInactive();

// 3. Verify the listener receives the IO error, NOT the graceful status
verify(clientTransportListener, timeout(5000)).transportShutdown(
org.mockito.ArgumentMatchers.argThat(status ->
status != null && status.getCause() instanceof java.io.IOException
),
org.mockito.ArgumentMatchers.any()
);
}


/**
* Verifies that we can create multiple TLS client transports from the same builder.
*/
Expand Down
Loading