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 <[email protected]>
(cherry picked from commit 41c2052)
  • Loading branch information
Ibrahim Jarif committed Sep 4, 2020
1 parent 88994d0 commit f898e62
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ var (

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

initDone uint32
)

func init() {
Expand Down Expand Up @@ -572,6 +574,7 @@ func setupServer(closer *z.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 @@ -751,7 +754,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 @@ -761,6 +770,8 @@ func run() {
updaters := z.NewCloser(2)
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 f898e62

Please sign in to comment.