Skip to content

Commit

Permalink
icyci: avoid timer deadlock in transitionState
Browse files Browse the repository at this point in the history
If stateTransTimer has already been stopped (without reset) then drain
will deadlock. Avoid this by using a select + default case, as done in
golang/go#27169 .

Signed-off-by: David Disseldorp <[email protected]>
  • Loading branch information
ddiss committed Nov 14, 2019
1 parent 88a5792 commit 7bf1c21
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion icyci.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,11 @@ func transitionState(newState State, curState *State,
*curState = newState

if !stateTransTimer.Stop() {
<-stateTransTimer.C
// select + default to avoid deadlock when already stopped
select {
case <-stateTransTimer.C:
default:
}
}
if states[newState].timeout == time.Duration(0) {
log.Printf("state %d doesn't timeout", newState)
Expand Down

0 comments on commit 7bf1c21

Please sign in to comment.