Skip to content
/ etcd Public
forked from etcd-io/etcd

Commit

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

Signed-off-by: Gyu-Ho Lee <[email protected]>
  • Loading branch information
gyuho committed Apr 15, 2017
1 parent e2d0db9 commit 981f9ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions etcdserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type ServerConfig struct {
ClientCertAuthEnabled bool

AuthToken string

// OnShutdown is called immediately before releasing etcd server resources.
OnShutdown func()
}

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

defer func() {
if s.Cfg != nil && s.Cfg.OnShutdown != nil {
// gRPC server stops accepting new connections,
// RPCs, and blocks until all pending RPCs are finished
// TODO: drain other pending requests?
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 981f9ec

Please sign in to comment.