forked from quic-go/quic-go
fix busy-looping in OpenStreamSync
This commit is contained in:
@@ -106,6 +106,7 @@ func (m *outgoingBidiStreamsMap) OpenStreamSync(ctx context.Context) (streamI, e
|
||||
}
|
||||
str := m.openStream()
|
||||
delete(m.openQueue, queuePos)
|
||||
m.lowestInQueue = queuePos + 1
|
||||
m.unblockOpenSync()
|
||||
return str, nil
|
||||
}
|
||||
@@ -172,8 +173,10 @@ func (m *outgoingBidiStreamsMap) SetMaxStream(num protocol.StreamNum) {
|
||||
m.maxStream = num
|
||||
m.blockedSent = false
|
||||
m.unblockOpenSync()
|
||||
// TODO(#2826): it might be necessary to send a STREAMS_BLOCKED frame
|
||||
}
|
||||
|
||||
// unblockOpenSync unblocks the next OpenStreamSync go-routine to open a new stream
|
||||
func (m *outgoingBidiStreamsMap) unblockOpenSync() {
|
||||
if len(m.openQueue) == 0 {
|
||||
return
|
||||
@@ -183,9 +186,12 @@ func (m *outgoingBidiStreamsMap) unblockOpenSync() {
|
||||
if !ok { // entry was deleted because the context was canceled
|
||||
continue
|
||||
}
|
||||
close(c)
|
||||
m.openQueue[qp] = nil
|
||||
m.lowestInQueue = qp + 1
|
||||
// unblockOpenSync is called both from OpenStreamSync and from SetMaxStream.
|
||||
// It's sufficient to only unblock OpenStreamSync once.
|
||||
select {
|
||||
case c <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user