Skip to content

Commit

Permalink
fix a potential logic race
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Apr 18, 2019
1 parent 11b388c commit d568d23
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,14 @@ func (s *Session) OpenStream() (*Stream, error) {
}

s.streamLock.Lock()
s.streams[sid] = stream
s.streamLock.Unlock()
return stream, nil
defer s.streamLock.Unlock()
select {
case <-s.die:
return nil, errors.New(errBrokenPipe)
default:
s.streams[sid] = stream
return stream, nil
}
}

// AcceptStream is used to block until the next available stream
Expand Down

0 comments on commit d568d23

Please sign in to comment.