تخطَّ إلى المحتوى

Goroutine Leak (ARCH5033)

هذا المحتوى غير متوفر بلغتك بعد.

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.

func Start(ch chan int) {
go func() {
for {
v := <-ch // blocks forever once the sender stops
process(v)
}
}()
}
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.