Always stop timer in Stream.Read

Resolves https://github.com/xtaci/smux/issues/52
This commit is contained in:
Joesis
2019-07-09 19:01:50 -07:00
parent 79b3c96b84
commit e7738d03db
+2 -3
View File
@@ -84,14 +84,13 @@ func (s *Stream) Read(b []byte) (n int, err error) {
var deadline <-chan time.Time
if d, ok := s.readDeadline.Load().(time.Time); ok && !d.IsZero() {
timer = time.NewTimer(time.Until(d))
defer timer.Stop()
deadline = timer.C
}
select {
case <-s.chReadEvent:
if timer != nil {
timer.Stop()
}
continue
case <-s.chFinEvent:
return 0, errors.WithStack(io.EOF)
case <-s.sess.chSocketReadError: