Skip to content

Commit

Permalink
fix(stream): avoid taking the receive lock while holding the state lock
Browse files Browse the repository at this point in the history
fixes #7
  • Loading branch information
Stebalien committed Oct 22, 2019
1 parent 6639721 commit 8912b9d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ func (s *Stream) Read(b []byte) (n int, err error) {
defer asyncNotify(s.recvNotifyCh)
START:
s.stateLock.Lock()
switch s.state {
state := s.state
s.stateLock.Unlock()

switch state {
case streamRemoteClose:
fallthrough
case streamClosed:
s.recvLock.Lock()
if s.recvBuf.Len() == 0 {
s.recvLock.Unlock()
s.stateLock.Unlock()
empty := s.recvBuf.Len() == 0
s.recvLock.Unlock()
if empty {
return 0, io.EOF
}
s.recvLock.Unlock()
case streamReset:
s.stateLock.Unlock()
return 0, ErrConnectionReset
}
s.stateLock.Unlock()

// If there is no data available, block
s.recvLock.Lock()
Expand Down

0 comments on commit 8912b9d

Please sign in to comment.