Skip to content

Commit

Permalink
Merge pull request #127 from lattwood/lattwood/handle_shutdown_edgecase
Browse files Browse the repository at this point in the history
Streams should check for Session shutdown when waiting for data & clean up timers
  • Loading branch information
schmichael authored Sep 5, 2024
2 parents 8bd691f + 84b3fc6 commit b5c3b44
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,17 @@ WAIT:
timeout = timer.C
}
select {
case <-s.session.shutdownCh:
case <-s.recvNotifyCh:
if timer != nil {
timer.Stop()
}
goto START
case <-timeout:
return 0, ErrTimeout
}
if timer != nil {
if !timer.Stop() {
<-timeout
}
}
goto START
}

// Write is used to write to the stream
Expand Down Expand Up @@ -219,17 +222,25 @@ START:

WAIT:
var timeout <-chan time.Time
var timer *time.Timer
writeDeadline := s.writeDeadline.Load().(time.Time)
if !writeDeadline.IsZero() {
delay := time.Until(writeDeadline)
timeout = time.After(delay)
timer = time.NewTimer(delay)
timeout = timer.C
}
select {
case <-s.session.shutdownCh:
case <-s.sendNotifyCh:
goto START
case <-timeout:
return 0, ErrTimeout
}
if timer != nil {
if !timer.Stop() {
<-timeout
}
}
goto START
}

// sendFlags determines any flags that are appropriate
Expand Down

0 comments on commit b5c3b44

Please sign in to comment.