Skip to content

Commit 7bf1c21

Browse files
committed
icyci: avoid timer deadlock in transitionState
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]>
1 parent 88a5792 commit 7bf1c21

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

icyci.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,11 @@ func transitionState(newState State, curState *State,
419419
*curState = newState
420420

421421
if !stateTransTimer.Stop() {
422-
<-stateTransTimer.C
422+
// select + default to avoid deadlock when already stopped
423+
select {
424+
case <-stateTransTimer.C:
425+
default:
426+
}
423427
}
424428
if states[newState].timeout == time.Duration(0) {
425429
log.Printf("state %d doesn't timeout", newState)

0 commit comments

Comments
 (0)