mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-06 21:57:36 +03:00
fix race condition in GetStream in outgoing streams map
This commit is contained in:
parent
77a4bf17ca
commit
4fa68b0788
6 changed files with 15 additions and 3 deletions
|
@ -85,6 +85,9 @@ func (m *incomingBidiStreamsMap) GetOrOpenStream(id protocol.StreamID) (streamI,
|
||||||
m.mutex.RUnlock()
|
m.mutex.RUnlock()
|
||||||
|
|
||||||
m.mutex.Lock()
|
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
|
var start protocol.StreamID
|
||||||
if m.highestStream == 0 {
|
if m.highestStream == 0 {
|
||||||
start = m.nextStream
|
start = m.nextStream
|
||||||
|
|
|
@ -83,6 +83,9 @@ func (m *incomingItemsMap) GetOrOpenStream(id protocol.StreamID) (item, error) {
|
||||||
m.mutex.RUnlock()
|
m.mutex.RUnlock()
|
||||||
|
|
||||||
m.mutex.Lock()
|
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
|
var start protocol.StreamID
|
||||||
if m.highestStream == 0 {
|
if m.highestStream == 0 {
|
||||||
start = m.nextStream
|
start = m.nextStream
|
||||||
|
|
|
@ -85,6 +85,9 @@ func (m *incomingUniStreamsMap) GetOrOpenStream(id protocol.StreamID) (receiveSt
|
||||||
m.mutex.RUnlock()
|
m.mutex.RUnlock()
|
||||||
|
|
||||||
m.mutex.Lock()
|
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
|
var start protocol.StreamID
|
||||||
if m.highestStream == 0 {
|
if m.highestStream == 0 {
|
||||||
start = m.nextStream
|
start = m.nextStream
|
||||||
|
|
|
@ -85,10 +85,11 @@ func (m *outgoingBidiStreamsMap) openStreamImpl() (streamI, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *outgoingBidiStreamsMap) GetStream(id protocol.StreamID) (streamI, error) {
|
func (m *outgoingBidiStreamsMap) GetStream(id protocol.StreamID) (streamI, error) {
|
||||||
|
m.mutex.RLock()
|
||||||
if id >= m.nextStream {
|
if id >= m.nextStream {
|
||||||
|
m.mutex.RUnlock()
|
||||||
return nil, qerr.Error(qerr.InvalidStreamID, fmt.Sprintf("peer attempted to open stream %d", id))
|
return nil, qerr.Error(qerr.InvalidStreamID, fmt.Sprintf("peer attempted to open stream %d", id))
|
||||||
}
|
}
|
||||||
m.mutex.RLock()
|
|
||||||
s := m.streams[id]
|
s := m.streams[id]
|
||||||
m.mutex.RUnlock()
|
m.mutex.RUnlock()
|
||||||
return s, nil
|
return s, nil
|
||||||
|
|
|
@ -86,10 +86,11 @@ func (m *outgoingItemsMap) openStreamImpl() (item, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *outgoingItemsMap) GetStream(id protocol.StreamID) (item, error) {
|
func (m *outgoingItemsMap) GetStream(id protocol.StreamID) (item, error) {
|
||||||
|
m.mutex.RLock()
|
||||||
if id >= m.nextStream {
|
if id >= m.nextStream {
|
||||||
|
m.mutex.RUnlock()
|
||||||
return nil, qerr.Error(qerr.InvalidStreamID, fmt.Sprintf("peer attempted to open stream %d", id))
|
return nil, qerr.Error(qerr.InvalidStreamID, fmt.Sprintf("peer attempted to open stream %d", id))
|
||||||
}
|
}
|
||||||
m.mutex.RLock()
|
|
||||||
s := m.streams[id]
|
s := m.streams[id]
|
||||||
m.mutex.RUnlock()
|
m.mutex.RUnlock()
|
||||||
return s, nil
|
return s, nil
|
||||||
|
|
|
@ -85,10 +85,11 @@ func (m *outgoingUniStreamsMap) openStreamImpl() (sendStreamI, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *outgoingUniStreamsMap) GetStream(id protocol.StreamID) (sendStreamI, error) {
|
func (m *outgoingUniStreamsMap) GetStream(id protocol.StreamID) (sendStreamI, error) {
|
||||||
|
m.mutex.RLock()
|
||||||
if id >= m.nextStream {
|
if id >= m.nextStream {
|
||||||
|
m.mutex.RUnlock()
|
||||||
return nil, qerr.Error(qerr.InvalidStreamID, fmt.Sprintf("peer attempted to open stream %d", id))
|
return nil, qerr.Error(qerr.InvalidStreamID, fmt.Sprintf("peer attempted to open stream %d", id))
|
||||||
}
|
}
|
||||||
m.mutex.RLock()
|
|
||||||
s := m.streams[id]
|
s := m.streams[id]
|
||||||
m.mutex.RUnlock()
|
m.mutex.RUnlock()
|
||||||
return s, nil
|
return s, nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue