Skip to content

Commit

Permalink
etcdserver: add 'OnShutdown', stop gRPC server
Browse files Browse the repository at this point in the history
Fix #7322.

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Apr 14, 2017
1 parent 90babfc commit 6e207e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions etcdserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ type ServerConfig struct {
ClientCertAuthEnabled bool

AuthToken string

// OnShutdown gracefully stops gRPC server on shutdown.
// It first stops accepting new connections, RPCs, and
// blocks until all pending RPCs are finished
// TODO: drain other requests
OnShutdown func()
}

// VerifyBootstrap sanity-checks the initial config for bootstrap case
Expand Down
6 changes: 6 additions & 0 deletions etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,12 @@ func (s *EtcdServer) run() {
}

defer func() {
// stop accepting new connections, RPCs,
// and blocks until all pending RPCs are finished
if s.Cfg.OnShutdown != nil {
s.Cfg.OnShutdown()
}

s.wgMu.Lock() // block concurrent waitgroup adds in goAttach while stopping
close(s.stopping)
s.wgMu.Unlock()
Expand Down

0 comments on commit 6e207e4

Please sign in to comment.