-
Notifications
You must be signed in to change notification settings - Fork 215
[AN] Remove readiness blocking on gracefulDone channel
#8664
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
Merged
+24
−4
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,12 +39,21 @@ var blockingStreamServiceDesc = grpc.ServiceDesc{ | |
| type blockingStreamServer struct { | ||
| // started is closed when the stream handler has been entered. | ||
| started chan struct{} | ||
| // blockDuration will cause `Stream` to block for the set duration | ||
| blockDuration time.Duration | ||
| } | ||
|
|
||
| var _ blockingStreamService = (*blockingStreamServer)(nil) | ||
|
|
||
| func (s *blockingStreamServer) Stream(stream grpc.ServerStream) error { | ||
| close(s.started) | ||
| if s.blockDuration > 0 { | ||
| // this is to simulate the case that after `grpcServer.Stop()` is called, | ||
| // `<-gracefulDone` channel is still blocking, so that we can verify | ||
| // the caller is not waiting for `<-gracefulDone` return before shutdown, | ||
| // otherwise, the waiting might be still blocking for longer or indefinitely. | ||
| time.Sleep(s.blockDuration) | ||
|
m-Peter marked this conversation as resolved.
|
||
| } | ||
| <-stream.Context().Done() | ||
| return nil | ||
| } | ||
|
|
@@ -60,7 +69,10 @@ func TestGrpcServerShutdown_WithActiveStream(t *testing.T) { | |
| gracefulStopTimeout := 200 * time.Millisecond | ||
|
|
||
| rawServer := grpc.NewServer() | ||
| handler := &blockingStreamServer{started: make(chan struct{})} | ||
| handler := &blockingStreamServer{ | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By adding could not close done channel on time: failed to shutdown all components on timeshowcasing the blocking that was still possible. |
||
| started: make(chan struct{}), | ||
| blockDuration: gracefulStopTimeout * 10, | ||
| } | ||
| rawServer.RegisterService(&blockingStreamServiceDesc, handler) | ||
|
|
||
| signalerCtx := atomic.NewPointer[irrecoverable.SignalerContext](nil) | ||
|
|
@@ -114,7 +126,10 @@ func TestGrpcServerShutdown_ShutdownStreamInterceptor(t *testing.T) { | |
| rawServer := grpc.NewServer( | ||
| grpc.ChainStreamInterceptor(grpcserver.ShutdownStreamInterceptor(signalerCtx)), | ||
| ) | ||
| handler := &blockingStreamServer{started: make(chan struct{})} | ||
| handler := &blockingStreamServer{ | ||
| started: make(chan struct{}), | ||
| blockDuration: time.Second, | ||
| } | ||
| rawServer.RegisterService(&blockingStreamServiceDesc, handler) | ||
|
|
||
| server := grpcserver.NewGrpcServer( | ||
|
|
@@ -159,7 +174,13 @@ func TestGrpcServerShutdown_NoActiveStreams(t *testing.T) { | |
| gracefulStopTimeout := 5 * time.Second | ||
|
|
||
| rawServer := grpc.NewServer() | ||
| rawServer.RegisterService(&blockingStreamServiceDesc, &blockingStreamServer{started: make(chan struct{})}) | ||
| rawServer.RegisterService( | ||
| &blockingStreamServiceDesc, | ||
| &blockingStreamServer{ | ||
| started: make(chan struct{}), | ||
| blockDuration: gracefulStopTimeout * 10, | ||
| }, | ||
| ) | ||
|
|
||
| signalerCtx := atomic.NewPointer[irrecoverable.SignalerContext](nil) | ||
| server := grpcserver.NewGrpcServer( | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Besides blocking on the
donechannel readiness, also add some artificial blocking withtime.Sleep, whenever configured.