From e7738d03db71fee06ef816bf15b055b5f7ceaeeb Mon Sep 17 00:00:00 2001 From: Joesis Date: Tue, 9 Jul 2019 19:01:50 -0700 Subject: [PATCH] Always stop timer in Stream.Read Resolves https://github.com/xtaci/smux/issues/52 --- stream.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stream.go b/stream.go index 6ccc864..8d7bbfa 100644 --- a/stream.go +++ b/stream.go @@ -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: