Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streams should check for Session shutdown when waiting for data & clean up timers #127

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading