forked from quic-go/quic-go
fix race condition in GetStream in outgoing streams map
This commit is contained in:
@@ -85,6 +85,9 @@ func (m *incomingBidiStreamsMap) GetOrOpenStream(id protocol.StreamID) (streamI,
|
||||
m.mutex.RUnlock()
|
||||
|
||||
m.mutex.Lock()
|
||||
// no need to check the two error conditions from above again
|
||||
// * maxStream can only increase, so if the id was valid before, it definitely is valid now
|
||||
// * highestStream is only modified by this function
|
||||
var start protocol.StreamID
|
||||
if m.highestStream == 0 {
|
||||
start = m.nextStream
|
||||
|
||||
@@ -83,6 +83,9 @@ func (m *incomingItemsMap) GetOrOpenStream(id protocol.StreamID) (item, error) {
|
||||
m.mutex.RUnlock()
|
||||
|
||||
m.mutex.Lock()
|
||||
// no need to check the two error conditions from above again
|
||||
// * maxStream can only increase, so if the id was valid before, it definitely is valid now
|
||||
// * highestStream is only modified by this function
|
||||
var start protocol.StreamID
|
||||
if m.highestStream == 0 {
|
||||
start = m.nextStream
|
||||
|
||||
@@ -85,6 +85,9 @@ func (m *incomingUniStreamsMap) GetOrOpenStream(id protocol.StreamID) (receiveSt
|
||||
m.mutex.RUnlock()
|
||||
|
||||
m.mutex.Lock()
|
||||
// no need to check the two error conditions from above again
|
||||
// * maxStream can only increase, so if the id was valid before, it definitely is valid now
|
||||
// * highestStream is only modified by this function
|
||||
var start protocol.StreamID
|
||||
if m.highestStream == 0 {
|
||||
start = m.nextStream
|
||||
|
||||
@@ -85,10 +85,11 @@ func (m *outgoingBidiStreamsMap) openStreamImpl() (streamI, error) {
|
||||
}
|
||||
|
||||
func (m *outgoingBidiStreamsMap) GetStream(id protocol.StreamID) (streamI, error) {
|
||||
m.mutex.RLock()
|
||||
if id >= m.nextStream {
|
||||
m.mutex.RUnlock()
|
||||
return nil, qerr.Error(qerr.InvalidStreamID, fmt.Sprintf("peer attempted to open stream %d", id))
|
||||
}
|
||||
m.mutex.RLock()
|
||||
s := m.streams[id]
|
||||
m.mutex.RUnlock()
|
||||
return s, nil
|
||||
|
||||
@@ -86,10 +86,11 @@ func (m *outgoingItemsMap) openStreamImpl() (item, error) {
|
||||
}
|
||||
|
||||
func (m *outgoingItemsMap) GetStream(id protocol.StreamID) (item, error) {
|
||||
m.mutex.RLock()
|
||||
if id >= m.nextStream {
|
||||
m.mutex.RUnlock()
|
||||
return nil, qerr.Error(qerr.InvalidStreamID, fmt.Sprintf("peer attempted to open stream %d", id))
|
||||
}
|
||||
m.mutex.RLock()
|
||||
s := m.streams[id]
|
||||
m.mutex.RUnlock()
|
||||
return s, nil
|
||||
|
||||
@@ -85,10 +85,11 @@ func (m *outgoingUniStreamsMap) openStreamImpl() (sendStreamI, error) {
|
||||
}
|
||||
|
||||
func (m *outgoingUniStreamsMap) GetStream(id protocol.StreamID) (sendStreamI, error) {
|
||||
m.mutex.RLock()
|
||||
if id >= m.nextStream {
|
||||
m.mutex.RUnlock()
|
||||
return nil, qerr.Error(qerr.InvalidStreamID, fmt.Sprintf("peer attempted to open stream %d", id))
|
||||
}
|
||||
m.mutex.RLock()
|
||||
s := m.streams[id]
|
||||
m.mutex.RUnlock()
|
||||
return s, nil
|
||||
|
||||
Reference in New Issue
Block a user