diff options
author | Alex Auvolat <alex@adnab.me> | 2020-03-04 17:44:22 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-03-04 17:44:22 +0100 |
commit | d4d3cc422b809d17daa18966ac95a852fc3045a5 (patch) | |
tree | e54ee18524568902b3d183a61d83d603ca78f6ab /connector/external | |
parent | df1f2d38b3e5d31827bf1d07fa63d5eaed6bc682 (diff) | |
download | easybridge-d4d3cc422b809d17daa18966ac95a852fc3045a5.tar.gz easybridge-d4d3cc422b809d17daa18966ac95a852fc3045a5.zip |
Improve exiting (actually it was Mattermost that was creating a deadlock)
Diffstat (limited to 'connector/external')
-rw-r--r-- | connector/external/external.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/connector/external/external.go b/connector/external/external.go index b66ab6c..9896750 100644 --- a/connector/external/external.go +++ b/connector/external/external.go @@ -177,6 +177,7 @@ func (ext *External) restartLoop(generation int) { break } log.Printf("Process %s stopped, restarting.", ext.command) + log.Printf("Generation %d vs %d", ext.generation, generation) err := ext.setupProc(generation) if err != nil { ext.proc = nil @@ -326,22 +327,23 @@ func (ext *External) Close() { ext.sendJson.Encode(&extMessage{ MsgType: CLOSE, }) + ext.proc.Process.Signal(os.Interrupt) - proc := ext.proc - proc.Process.Signal(os.Interrupt) ext.recvPipe.Close() ext.sendPipe.Close() + go func() { + time.Sleep(1 * time.Second) + log.Info("Sending SIGKILL to external process (did not terminate within 1 second)") + ext.proc.Process.Kill() + }() + ext.proc.Wait() + ext.proc = nil ext.recvPipe = nil ext.sendPipe = nil ext.sendJson = nil ext.handlerChan = nil - - go func() { - time.Sleep(1 * time.Second) - proc.Process.Kill() - }() } // ---- Actual message handling :) |