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

fix inconsistent locking of mutexes by holding the stateLock for shorter #98

Merged
merged 1 commit into from
Sep 6, 2022
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
14 changes: 11 additions & 3 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,40 +385,48 @@ func (s *Stream) cleanup() {
// based on set flags, if any. Lock must be held
func (s *Stream) processFlags(flags uint16) {
// Close the stream without holding the state lock
closeStream := false
var closeStream bool
defer func() {
if closeStream {
s.cleanup()
}
}()

s.stateLock.Lock()
defer s.stateLock.Unlock()
if flags&flagACK == flagACK {
s.stateLock.Lock()
if s.state == streamSYNSent {
s.state = streamEstablished
}
s.stateLock.Unlock()
s.session.establishStream(s.id)
}
if flags&flagFIN == flagFIN {
var notify bool
s.stateLock.Lock()
if s.readState == halfOpen {
s.readState = halfClosed
if s.writeState != halfOpen {
// We're now fully closed.
closeStream = true
s.state = streamFinished
}
notify = true
}
s.stateLock.Unlock()
if notify {
s.notifyWaiting()
}
}
if flags&flagRST == flagRST {
s.stateLock.Lock()
if s.readState == halfOpen {
s.readState = halfReset
}
if s.writeState == halfOpen {
s.writeState = halfReset
}
s.state = streamFinished
s.stateLock.Unlock()
closeStream = true
s.notifyWaiting()
}
Expand Down