Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am skwair on github.
  • I am skwair (https://keybase.io/skwair) on keybase.
  • I have a public key ASCLu3W-ojFUHrk-et665iSiM4y4AwlsLGWEyYOHTMPXVAo

To claim this, I am signing this object:

@skwair
skwair / grpc_graceful.go
Created May 1, 2018 12:04
gRPC Graceful stop with context.
// shutdown adds a context.Context to the GracefulStop method of
// grpc.Server, allowing to set a timeout before calling Stop.
func shutdown(ctx context.Context, s *grpc.Server) error {
ok := make(chan struct{})
// NOTE: GracefulStop will return instantly
// when Stop it called, preventing this
// goroutine from leaking.
go func() {
s.GracefulStop()
close(ok)