Skip to content

Potential Goroutine Leak Due to Unbuffered Channel

Description

The code has a potential goroutine leak due to an unbuffered channel send inside a loop or an unbuffered channel receive in a select block. This can cause the program to hang or deadlock.

Examples

Insecure Code

go
go func() { ch := make(chan int); go func() { for { ch <- 1 } }(); }()

Secure Code

go
go func() { ch := make(chan int, 1); go func() { for { ch <- 1 } }(); }()

Remediation

Use a buffered channel or ensure that the channel is properly closed to prevent goroutine leaks.

Rule Details

FieldValue
IDCODE-0667
CategoryConcurrency
SeverityMEDIUM
CWECWE-833
ConfidenceMEDIUM
ImpactLOW
LikelihoodMEDIUM
ExploitabilityCOMPLEX
Tagsgoroutine leak, unbuffered channel
OWASPN/A

References