Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove the recvLock in the stream #42

Merged
merged 1 commit into from
Feb 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
remove the recvLock in the stream
Concurrent use of an io.Reader is not valid.
  • Loading branch information
marten-seemann committed Feb 17, 2021
commit 5432a2461e81fc547c6ac75be95fab573df79cd0
8 changes: 2 additions & 6 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand All @@ -110,7 +107,6 @@ START:

// Read any bytes
n, _ = s.recvBuf.Read(b)
s.recvLock.Unlock()

// Send a window update potentially
err = s.sendWindowUpdate()
Expand Down Expand Up @@ -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
}
Expand Down