Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: fix race causing streams to be terminated by GracefulStop #2857

Merged
merged 3 commits into from
Jun 12, 2019

Conversation

menghanl
Copy link
Contributor

@menghanl menghanl commented Jun 8, 2019

Before this fix, stream is removed from activeStreams in finishStream,
which happens when the service handler returns status, without waiting
for the status to be sent by loopyWriter. If GracefulStop() is called in
between, it will close the connection (because activeStreams is empty),
which causes the RPC to fail with "transport is closing". This change
moves the activeStreams cleanup into loopyWriter, after sending status
on wire.

fixes #2703

…velly

Before this fix, stream is removed from activeStreams in finishStream,
which happens when the service handler returns status, without waiting
for the status to be sent by loopyWriter. If GracefulStop() is called in
between, it will close the connection (because activeStreams is empty),
which causes the RPC to fail with "transport is closing". This change
moves the activeStreams cleanup into loopyWriter, after sending status
on wire.
// In case stream sending and receiving are invoked in separate
// goroutines (e.g., bi-directional streaming), cancel needs to be
// called to interrupt the potential blocking on other goroutines.
s.cancel()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to keep s.cancel() in deleteStream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Done.

@@ -1020,17 +1020,6 @@ func (t *http2Server) Close() error {

// deleteStream deletes the stream s from transport's active streams.
func (t *http2Server) deleteStream(s *Stream, eosReceived bool) (oldState streamState) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need to return anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link

@canguler canguler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@menghanl menghanl merged commit cd89eaf into grpc:master Jun 12, 2019
@menghanl menghanl deleted the Test_GracefulStop branch June 12, 2019 17:26
@menghanl menghanl added this to the 1.22 Release milestone Jun 20, 2019
@dfawley dfawley changed the title test: fix Test/GracefulStop by not removing activeStreams too aggresivelly server: fix race causing streams to be terminated by GracefulStop Jul 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unflake GracefulStop
3 participants