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

Can GracefulStop have a timeout? #2448

Closed
ceshihao opened this issue Nov 9, 2018 · 1 comment
Closed

Can GracefulStop have a timeout? #2448

ceshihao opened this issue Nov 9, 2018 · 1 comment

Comments

@ceshihao
Copy link

ceshihao commented Nov 9, 2018

Please answer these questions before submitting your issue.

What version of gRPC are you using?

gRPC 1.7

What version of Go are you using (go version)?

go version go1.9.5 darwin/amd64

What operating system (Linux, Windows, …) and version?

MacOS Mojave 10.14

What did you do?

Use GracefulStop to stop gRPC Server. It blocks until all the pending RPCs are finished.

However, if some RPC is abnormally pending for a long time, the server has to wait.
Can I set timout for the GracefulStop?

What did you expect to see?

The server can be stop by GracefulStop timeout, if some RPC is abnormally pending for a long time.

What did you see instead?

@menghanl
Copy link
Contributor

menghanl commented Nov 9, 2018

This can be done by running GracefulStop in a goroutine, and do a select-wait on timer followed by a force Stop in the main goroutine.

Something like:

stopped := make(chan, struct{})
go func () {
  s.GracefulStop()
  close(stopped)
}

t := time.NewTimer(10 * time.Second)
select {
case <- t.C:
  s.Stop()
case <- stopped:
  t.Stop()
}

@menghanl menghanl closed this as completed Nov 9, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants