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) (#6408)

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 authored Sep 4, 2020
1 parent ddf71e0 commit db1fc38
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"os/signal"
"strings"
"sync"
"sync/atomic"
"syscall"
"time"

Expand Down Expand Up @@ -74,7 +75,8 @@ var (
startTime = time.Now()

// Alpha is the sub-command invoked when running "dgraph alpha".
Alpha x.SubCommand
Alpha x.SubCommand
initDone uint32
)

func init() {
Expand Down Expand Up @@ -516,6 +518,7 @@ func setupServer() {

glog.Infoln("gRPC server started. Listening on port", grpcPort())
glog.Infoln("HTTP server started. Listening on port", httpPort())
atomic.AddUint32(&initDone, 1)
wg.Wait()
}

Expand Down Expand Up @@ -691,7 +694,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 @@ -702,6 +711,8 @@ func run() {
aclCloser := z.NewCloser(1)
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()
Expand Down

0 comments on commit db1fc38

Please sign in to comment.