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
| Field | Value |
|---|---|
| ID | CODE-0667 |
| Category | Concurrency |
| Severity | MEDIUM |
| CWE | CWE-833 |
| Confidence | MEDIUM |
| Impact | LOW |
| Likelihood | MEDIUM |
| Exploitability | COMPLEX |
| Tags | goroutine leak, unbuffered channel |
| OWASP | N/A |