Browse Source

Make sure to drain the timer channel on defer, and a clarifying comment

Preetha Appan 7 năm trước cách đây
mục cha
commit
f21aae5366
1 tập tin đã thay đổi với 9 bổ sung0 xóa
  1. 9 0
      session.go

+ 9 - 0
session.go

@@ -334,6 +334,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)
 	}()
 
@@ -365,6 +369,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)
 	}()
 
@@ -424,6 +432,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,