From 9a1b52171fc79bd99368aa60f0e9cc7f0ad57155 Mon Sep 17 00:00:00 2001 From: Wojciech Bederski Date: Thu, 17 Sep 2015 11:32:08 +0200 Subject: [PATCH] panic when unbalanced localState.Resume() is detected --- command/agent/local.go | 5 ++++- command/agent/local_test.go | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/command/agent/local.go b/command/agent/local.go index 310b055ab..3dd8f6471 100644 --- a/command/agent/local.go +++ b/command/agent/local.go @@ -114,7 +114,10 @@ func (l *localState) Pause() { // Resume is used to resume state synchronization func (l *localState) Resume() { - atomic.AddInt32(&l.paused, -1) + paused := atomic.AddInt32(&l.paused, -1) + if paused < 0 { + panic("unbalanced localState.Resume() detected") + } l.changeMade() } diff --git a/command/agent/local_test.go b/command/agent/local_test.go index bc525d278..47d8f8f3e 100644 --- a/command/agent/local_test.go +++ b/command/agent/local_test.go @@ -685,6 +685,15 @@ func TestAgent_nestedPauseResume(t *testing.T) { if l.isPaused() != false { t.Fatal("localState should NOT be Paused after SECOND call to Resume()") } + + defer func() { + err := recover() + if err == nil { + t.Fatal("unbalanced Resume() should cause a panic()") + } + }() + l.Resume() + } var testRegisterRules = `