Goroutine Leak (ARCH5033)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key go.async.goroutine-leak · Severity warning · Category async
A goroutine launched with no termination path - a blocking channel send or receive without a select plus context.Done() - never exits. These leaked goroutines hold memory and channel resources for the life of the process.
Incorrect
Section titled “Incorrect”func Start(ch chan int) { go func() { for { v := <-ch // blocks forever once the sender stops process(v) } }()}Correct
Section titled “Correct”func Start(ctx context.Context, ch chan int) { go func() { for { select { case v := <-ch: process(v) case <-ctx.Done(): return } } }()}Give the goroutine loop a select with a <-ctx.Done() exit branch.