From 3458e655c0ffb2143e81793a63b6ade219be0d6b Mon Sep 17 00:00:00 2001 From: postmannen Date: Thu, 23 Jun 2022 11:40:17 +0200 Subject: [PATCH] fixed proper stop and removal of subscriber procs --- process.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/process.go b/process.go index 1340c59..1a1d2e2 100644 --- a/process.go +++ b/process.go @@ -227,6 +227,25 @@ func (p process) spawnWorker() { } p.natsSubscription = p.subscribeMessages() + + // We also need to be able to remove all the information about this process + // when the process context is canceled. + go func() { + <-p.ctx.Done() + err := p.natsSubscription.Unsubscribe() + if err != nil { + er := fmt.Errorf("error: spawnWorker: got <-ctx.Done, but unable to unsubscribe natsSubscription failed: %v", err) + p.errorKernel.errSend(p, Message{}, er) + p.errorKernel.logConsoleOnlyIfDebug(er, p.configuration) + } + + p.processes.active.mu.Lock() + delete(p.processes.active.procNames, p.processName) + p.processes.active.mu.Unlock() + + log.Printf("Successfully stopped process: %v\n", p.processName) + + }() } // Add information about the new process to the started processes map.