dgryski / semgrep-go

Go rules for semgrep and go-ruleguard
MIT License
457 stars 37 forks source link

catch potential deadlock #58

Open celrenheit opened 1 year ago

celrenheit commented 1 year ago

catch potential deadlock when the context is done but waiting to send on a channel in the default case

dgryski commented 1 year ago

Do you have an example where this actually happened?

celrenheit commented 1 year ago

I came across twice on an existing code doing:

select {
case <-ctx.Done():
// ...
default:
  ch <- 1
}

instead of

select {
case <-ctx.Done():
// ...
case ch <- 1:
}

This caused a deadlock blocking the exit.

I wasn't sure to open a PR for this, after using it to look for other issues like that, because it might raise false positives.