-
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
Serve() should not return error on Stop() or GracefulStop() #1485
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
23d8a89
to
1bc060d
Compare
CLAs look good, thanks! |
Sorry for the late reply, and thanks for the change. The changes in this PR look good. |
Hi @menghanl thanks for the reply! Originally I hesitated to block I think it'll be easier for me to do it in the same PR, I will make a new commit! |
b8d6e06
to
fbf482e
Compare
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.
Can you add some tests for this new behavior?
Thanks!
|
||
// If Stop or GracefulStop is called, block until they are done and return nil | ||
select { | ||
case <-s.quit: |
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.
A server can actually Serve
on multiple listeners. This only works in the case of one Serve
.
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.
ah good catch, will fix!
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.
@menghanl Fixed by using a sync.Once
to close the channels, this way when s.quit
or s.done
is closed, all go-routines running Serve()
will be unblocked.
fbf482e
to
939f1c7
Compare
|
||
err = server.Serve(lis) | ||
if err != nil { | ||
t.Fatalf("Serve() returned non-nil error on GracefulStop: %v", err) |
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.
hey @menghanl I only added test for testing Serve()
should return nil on GracefulStop()
.
I found it tricky to actually test the order of Serve
and GracefulStop
, the only way I can think of is to make both functions send a message to a shared channel when they return, and compare the order of the messages in the channel, but this requires modifying Serve
and GracefulStop
themselves.
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.
One way to test this is to make GracefulStop()
block by having a pending streaming RPC, and check that Serve()
doesn't return.
We have end2end tests that does similar things.
f756b42
to
e2c3696
Compare
hey @menghanl mind taking another look at this? thanks! |
Thank you for your pull request. Before we can look at your contribution, we need to ensure all contributors are covered by a Contributor License Agreement. After the following items are addressed, please respond with a new comment here, and the automated system will re-verify.
Regards, |
I signed |
e2c3696
to
388d7a2
Compare
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.
|
||
err = server.Serve(lis) | ||
if err != nil { | ||
t.Fatalf("Serve() returned non-nil error on GracefulStop: %v", err) |
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.
One way to test this is to make GracefulStop()
block by having a pending streaming RPC, and check that Serve()
doesn't return.
We have end2end tests that does similar things.
Thanks for the changes. I'm merging this PR as it has been delayed for a long time. |
As #1372 reported, currently
Serve()
function returns non-nil error whenStop()
orGracefulStop()
is called.This is because both
Stop
andGracefulStop
close the listener (net.Listener
) directly, which is still being blocked on theAccept()
call inServe()
. We can use aquit
channel to indicate that the grpc server is being stopped on demand and returnnil
instead of an error.