File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed
Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,9 @@ func (p *program) Start() error {
8787 // we don't want to un-register our sigterm handler which would
8888 // cause default go behavior to apply
8989 for range signalChan {
90- p .nsqd .TermSignal ()
90+ p .once .Do (func () {
91+ p .nsqd .Exit ()
92+ })
9193 }
9294 }()
9395 signal .Notify (signalChan , syscall .SIGTERM )
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ type NSQD struct {
5050
5151 dl * dirlock.DirLock
5252 isLoading int32
53+ isExiting int32
5354 errValue atomic.Value
5455 startTime time.Time
5556
@@ -402,13 +403,11 @@ func (n *NSQD) PersistMetadata() error {
402403 return nil
403404}
404405
405- // TermSignal handles a SIGTERM calling Exit
406- // This is a noop after first call
407- func (n * NSQD ) TermSignal () {
408- n .Exit ()
409- }
410-
411406func (n * NSQD ) Exit () {
407+ if ! atomic .CompareAndSwapInt32 (& n .isExiting , 0 , 1 ) {
408+ // avoid double call
409+ return
410+ }
412411 if n .tcpListener != nil {
413412 n .tcpListener .Close ()
414413 }
You can’t perform that action at this time.
0 commit comments