Skip to content

Commit

Permalink
fix(shutdown): Force exit if CTRL-C is caught before initialization (#…
Browse files Browse the repository at this point in the history
…6359)

Forcefully kill alpha if CTRL-C is caught before node initialization completes.

Fixes DGRAPH-2377

Co-authored-by: Manish R Jain <manish@dgraph.io>
  • Loading branch information
Ibrahim Jarif and manishrjain committed Sep 3, 2020
1 parent ea08797 commit 41c2052
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dgraph/cmd/alpha/run.go
Expand Up @@ -80,6 +80,8 @@ var (

// need this here to refer it in admin_backup.go
adminServer web.IServeGraphQL

initDone uint32
)

func init() {
Expand Down Expand Up @@ -588,6 +590,7 @@ func setupServer(closer *y.Closer) {
glog.Infoln("gRPC server started. Listening on port", grpcPort())
glog.Infoln("HTTP server started. Listening on port", httpPort())

atomic.AddUint32(&initDone, 1)
admin.ServerCloser.Wait()
}

Expand Down Expand Up @@ -767,7 +770,13 @@ func run() {
}
numShutDownSig++
glog.Infoln("Caught Ctrl-C. Terminating now (this may take a few seconds)...")
if numShutDownSig == 3 {

switch {
case atomic.LoadUint32(&initDone) < 2:
// Forcefully kill alpha if we haven't finish server initialization.
glog.Infoln("Stopped before initialization completed")
os.Exit(1)
case numShutDownSig == 3:
glog.Infoln("Signaled thrice. Aborting!")
os.Exit(1)
}
Expand All @@ -777,6 +786,8 @@ func run() {
updaters := y.NewCloser(4)
go func() {
worker.StartRaftNodes(worker.State.WALstore, bindall)
atomic.AddUint32(&initDone, 1)

// initialization of the admin account can only be done after raft nodes are running
// and health check passes
edgraph.ResetAcl(updaters)
Expand Down

0 comments on commit 41c2052

Please sign in to comment.