-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Conversation
…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.
internal/transport/http2_server.go
Outdated
// 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() |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Done.
internal/transport/http2_server.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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