From d0934737b67e17f9f64db2831482996c445d5ca9 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Fri, 6 Oct 2023 17:52:17 +0900 Subject: [PATCH] cshared: Make goroutine for Collect to be able to exit Signed-off-by: Hiroshi Hatake --- cshared.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cshared.go b/cshared.go index 35373c0..3c5a2b2 100644 --- a/cshared.go +++ b/cshared.go @@ -201,8 +201,16 @@ func prepareInputCollector() (err error) { go func(theChannel chan<- Message) { defer theInputLock.Unlock() + for { + select { + case <-runCtx.Done(): + log.Printf("goroutine will be stopping: name=%q\n", theName) + return + default: + err = theInput.Collect(runCtx, theChannel) + } + } - err := theInput.Collect(runCtx, theChannel) if err != nil { fmt.Fprintf(os.Stderr, "collect error: %s\n", err.Error())