From 5432a2461e81fc547c6ac75be95fab573df79cd0 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 16 Feb 2021 13:00:07 +0800 Subject: [PATCH] remove the recvLock in the stream Concurrent use of an io.Reader is not valid. --- stream.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/stream.go b/stream.go index e4bfb1a..b630b78 100644 --- a/stream.go +++ b/stream.go @@ -37,8 +37,7 @@ type Stream struct { writeState, readState halfStreamState stateLock sync.Mutex - recvLock sync.Mutex - recvBuf segmentedBuffer + recvBuf segmentedBuffer recvNotifyCh chan struct{} sendNotifyCh chan struct{} @@ -97,9 +96,7 @@ START: } // If there is no data available, block - s.recvLock.Lock() if s.recvBuf.Len() == 0 { - s.recvLock.Unlock() select { case <-s.recvNotifyCh: goto START @@ -110,7 +107,6 @@ START: // Read any bytes n, _ = s.recvBuf.Read(b) - s.recvLock.Unlock() // Send a window update potentially err = s.sendWindowUpdate() @@ -437,7 +433,7 @@ func (s *Stream) readData(hdr header, flags uint16, conn io.Reader) error { s.session.logger.Printf("[ERR] yamux: Failed to read stream data: %v", err) return err } - // Unblock any readers + // Unblock the reader asyncNotify(s.recvNotifyCh) return nil }