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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ func (m *outgoingItemsMap) OpenStreamSync(ctx context.Context) (item, error) {
|
||||
}
|
||||
str := m.openStream()
|
||||
delete(m.openQueue, queuePos)
|
||||
m.lowestInQueue = queuePos + 1
|
||||
m.unblockOpenSync()
|
||||
return str, nil
|
||||
}
|
||||
@@ -170,8 +171,10 @@ func (m *outgoingItemsMap) 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 *outgoingItemsMap) unblockOpenSync() {
|
||||
if len(m.openQueue) == 0 {
|
||||
return
|
||||
@@ -181,9 +184,12 @@ func (m *outgoingItemsMap) 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ func (m *outgoingUniStreamsMap) OpenStreamSync(ctx context.Context) (sendStreamI
|
||||
}
|
||||
str := m.openStream()
|
||||
delete(m.openQueue, queuePos)
|
||||
m.lowestInQueue = queuePos + 1
|
||||
m.unblockOpenSync()
|
||||
return str, nil
|
||||
}
|
||||
@@ -172,8 +173,10 @@ func (m *outgoingUniStreamsMap) 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 *outgoingUniStreamsMap) unblockOpenSync() {
|
||||
if len(m.openQueue) == 0 {
|
||||
return
|
||||
@@ -183,9 +186,12 @@ func (m *outgoingUniStreamsMap) 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