Skip to content

Commit

Permalink
Fix nginx-agent shutdown (#44)
Browse files Browse the repository at this point in the history
ProcessWatcher waitgroup was already decremented in it's go routine so
the wg.Done() in plugin.Close() led to panic due to negative waitgroup.

This means on SIGTERM/SIGINT the main nginx-agent process would exit
with status code 2 which is reported in systemd status.
  • Loading branch information
Dean-Coakley authored Sep 21, 2022
1 parent 9b0c6b6 commit d4dca2d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/plugins/process_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (pw *ProcessWatcher) Info() *core.Info {

func (pw *ProcessWatcher) Close() {
log.Info("ProcessWatcher is wrapping up")
pw.wg.Done()
pw.wg.Wait()
}

func (pw *ProcessWatcher) Process(message *core.Message) {}
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/process_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ func TestProcessWatcher_getProcUpdates(t *testing.T) {

func TestProcessWatcher_Process(t *testing.T) {
env := tutils.GetMockEnvWithProcess()

pluginUnderTest := NewProcessWatcher(env, tutils.GetMockNginxBinary())
messagePipe := core.SetupMockMessagePipe(t, context.TODO(), pluginUnderTest)

ctx, cancel := context.WithCancel(context.TODO())
messagePipe := core.SetupMockMessagePipe(t, ctx, pluginUnderTest)

pluginUnderTest.Init(messagePipe)
messagePipe.Run()
Expand All @@ -173,6 +174,8 @@ func TestProcessWatcher_Process(t *testing.T) {
}
}

cancel()

pluginUnderTest.Close()
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d4dca2d

Please sign in to comment.