Skip to content

Commit

Permalink
moar timer stopage fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Mar 2, 2022
1 parent f38e152 commit 152fa80
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions multiplex.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func (mp *Multiplex) handleIncoming() {

recvTimeout := time.NewTimer(0)
defer recvTimeout.Stop()
recvTimeoutFired := false

loop:
for {
Expand Down Expand Up @@ -475,11 +476,9 @@ loop:

rd += nextChunk

if !recvTimeout.Stop() {
select {
case <-recvTimeout.C:
default:
}
if !recvTimeout.Stop() && !recvTimeoutFired {
<-recvTimeout.C
recvTimeoutFired = false
}
recvTimeout.Reset(ReceiveTimeout)

Expand All @@ -496,6 +495,7 @@ loop:
break read

case <-recvTimeout.C:
recvTimeoutFired = true
mp.putBufferInbound(b)
log.Warnf("timed out receiving message into stream queue.")
// Do not do this asynchronously. Otherwise, we
Expand Down Expand Up @@ -604,19 +604,18 @@ func (mp *Multiplex) skipNextMsg(mlen int) error {
}

func (mp *Multiplex) getBufferInbound(length int) ([]byte, error) {
timerFired := false
defer func() {
if !mp.bufInTimer.Stop() {
select {
case <-mp.bufInTimer.C:
default:
}
if !mp.bufInTimer.Stop() && !timerFired {
<-mp.bufInTimer.C
}
}()
mp.bufInTimer.Reset(getInputBufferTimeout)

select {
case mp.bufIn <- struct{}{}:
case <-mp.bufInTimer.C:
timerFired = true
return nil, errTimeout
case <-mp.shutdown:
return nil, ErrShutdown
Expand Down

0 comments on commit 152fa80

Please sign in to comment.