Removed race condition

If two interrupts were fired really quickly interruptCount could have been incremented twice before the LoadUint32 making cleanup not being called at all.

Signed-off-by: Erik Dubbelboer <erik@dubbelboer.com>
Upstream-commit: 46b1194d996f6535e657bcb88428303305d3fe68
Component: engine
This commit is contained in:
Erik Dubbelboer
2014-12-06 22:52:19 +08:00
parent 93dd7fb297
commit c21c1c5984
+1 -2
View File
@@ -34,9 +34,8 @@ func Trap(cleanup func()) {
case os.Interrupt, syscall.SIGTERM:
// If the user really wants to interrupt, let him do so.
if atomic.LoadUint32(&interruptCount) < 3 {
atomic.AddUint32(&interruptCount, 1)
// Initiate the cleanup only once
if atomic.LoadUint32(&interruptCount) == 1 {
if atomic.AddUint32(&interruptCount, 1) == 1 {
// Call cleanup handler
cleanup()
os.Exit(0)