Skip to content

Conversation

@rmehta19
Copy link
Contributor

Wait for server response to be received before shutting down resources.

#12501

@ejona86 ejona86 self-requested a review November 25, 2025 05:23
@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Nov 25, 2025
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Nov 25, 2025
@ejona86
Copy link
Member

ejona86 commented Nov 25, 2025

Since the failures take less than 1 second, I think there's also a bug in the transport. Shutting down the channel should be safe, but shutting down the executor isn't safe until the RPC completes (so if awaitTermination() returns false, then things are probably busted). So we do need a change like this, but I'm also going to play with the test without this change to see if I can fix the problem in the channel.

@ejona86 ejona86 merged commit 2b9509e into grpc:master Nov 25, 2025
16 of 17 checks passed
ejona86 added a commit to ejona86/grpc-java that referenced this pull request Nov 25, 2025
This fixes a race where RPCs could fail with "UNAVAILABLE: Channel
shutdown invoked" even though they were created before
channel.shutdown().

This basically adopts the internalStart() logic from DelayedStream,
although the stream is a bit different because it has APIs that can be
called before start() and doesn't need to handle cancel() without
start().

The ManagedChannelImpltest had the number of due tasks increase because
start() running earlier creates a DelayedStream. Previously the stream
wasn't created until runDueTasks() so the mockPicker had already been
installed and it could use a real stream from the beginning. But that's
specific to the test; in practice it'd be a delayed stream before and
after this change.

See grpc#12536
ejona86 added a commit to ejona86/grpc-java that referenced this pull request Nov 25, 2025
This fixes a race where RPCs could fail with "UNAVAILABLE: Channel
shutdown invoked" even though they were created before
channel.shutdown().

This basically adopts the internalStart() logic from DelayedStream,
although the stream is a bit different because it has APIs that can be
called before start() and doesn't need to handle cancel() without
start().

The ManagedChannelImpltest had the number of due tasks increase because
start() running earlier creates a DelayedStream. Previously the stream
wasn't created until runDueTasks() so the mockPicker had already been
installed and it could use a real stream from the beginning. But that's
specific to the test; in practice it'd be a delayed stream before and
after this change.

See grpc#12536
@ejona86
Copy link
Member

ejona86 commented Nov 25, 2025

FYI: I am fixing the race in gRPC in #12539 . That change fixes the flake without this PR. (But this PR is still appropriate, for the other reasons I mentioned earlier.)

ejona86 added a commit that referenced this pull request Nov 26, 2025
This fixes a race where RPCs could fail with "UNAVAILABLE: Channel
shutdown invoked" even though they were created before
channel.shutdown().

This basically adopts the internalStart() logic from DelayedStream,
although the stream is a bit different because it has APIs that can be
called before start() and doesn't need to handle cancel() without
start().

The ManagedChannelImpltest had the number of due tasks increase because
start() running earlier creates a DelayedStream. Previously the stream
wasn't created until runDueTasks() so the mockPicker had already been
installed and it could use a real stream from the beginning. But that's
specific to the test; in practice it'd be a delayed stream before and
after this change.

See #12536
@shivaspeaks
Copy link
Member

The real flakiness is solved in #12539.
This PR fixed the incorrectness of a unit test as mentioned by Eric in earlier comment. Perhaps we should change the title and description of this PR in favor of the other PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants