Skip to content

Commit d568d23

Browse files
committed
fix a potential logic race
1 parent 11b388c commit d568d23

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

session.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,14 @@ func (s *Session) OpenStream() (*Stream, error) {
113113
}
114114

115115
s.streamLock.Lock()
116-
s.streams[sid] = stream
117-
s.streamLock.Unlock()
118-
return stream, nil
116+
defer s.streamLock.Unlock()
117+
select {
118+
case <-s.die:
119+
return nil, errors.New(errBrokenPipe)
120+
default:
121+
s.streams[sid] = stream
122+
return stream, nil
123+
}
119124
}
120125

121126
// AcceptStream is used to block until the next available stream

0 commit comments

Comments
 (0)