Skip to content

Commit

Permalink
Make sure to drain the timer channel on defer, and a clarifying comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Preetha Appan committed Mar 14, 2018
1 parent 5ddd520 commit 19c6e0d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ func (s *Session) waitForSendErr(hdr header, body io.Reader, errCh chan error) e
timer.Reset(s.config.ConnectionWriteTimeout)
defer func() {
timer.Stop()
select {
case <-timer.C:
default:
}
timerPool.Put(t)
}()

Expand Down Expand Up @@ -359,6 +363,10 @@ func (s *Session) sendNoWait(hdr header) error {
timer.Reset(s.config.ConnectionWriteTimeout)
defer func() {
timer.Stop()
select {
case <-timer.C:
default:
}
timerPool.Put(t)
}()

Expand Down Expand Up @@ -418,6 +426,7 @@ func (s *Session) recv() {
}
}

// Ensure that the index of the handler (typeData/typeWindowUpdate/etc) matches the message type
var (
handlers = []func(*Session, header) error{
typeData: (*Session).handleStreamMessage,
Expand Down

0 comments on commit 19c6e0d

Please sign in to comment.