Delay stream creation until the next loop tick (#416)

Motivation:

A recent change allowed stream creation to run immediately if the caller
was on the correct event loop. Normally that's fine, however, it opens
up a code path where streams can become activated twice which leads to a
crash.

Modifications:

- Delay stream creation until the next loop tick
- Add a loop tick to tests which now require it

Result:

Avoid re-entrantly activating streams twice.
This commit is contained in:
George Barnett authored and GitHub committed 2023-08-23 11:28:07 +01:00
1 parent 2bf57336ec
commit 92afa4fa84
8 files changed
+60 -50

No files matched your search

@@ -312,12 +312,11 @@ extension HTTP2CommonInboundStreamMultiplexer {
promise: EventLoopPromise<Output>?,
_ streamStateInitializer: @escaping NIOChannelInitializerWithOutput<Output>
) {
if self.channel.eventLoop.inEventLoop {
// Always create streams channels on the next event loop tick. This avoids re-entrancy
// issues where handlers interposed between the two HTTP/2 handlers could create streams
// in channel active which become activated twice.
self.channel.eventLoop.execute {
self._createStreamChannel(multiplexer, promise, streamStateInitializer)
} else {
self.channel.eventLoop.execute {
self._createStreamChannel(multiplexer, promise, streamStateInitializer)
}
}
}
@@ -354,12 +353,11 @@ extension HTTP2CommonInboundStreamMultiplexer {
promise: EventLoopPromise<Channel>?,
_ streamStateInitializer: @escaping (Channel) -> EventLoopFuture<Void>
) {
if self.channel.eventLoop.inEventLoop {
// Always create streams channels on the next event loop tick. This avoids re-entrancy
// issues where handlers interposed between the two HTTP/2 handlers could create streams
// in channel active which become activated twice.
self.channel.eventLoop.execute {
self._createStreamChannel(multiplexer, promise, streamStateInitializer)
} else {
self.channel.eventLoop.execute {
self._createStreamChannel(multiplexer, promise, streamStateInitializer)
}
}
}