-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Finish multiplexer's inbound streams in more cases #483
Finish multiplexer's inbound streams in more cases #483
Conversation
a9113e2
to
92bb298
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test for this too?
for channel in self.streams.values { | ||
channel.receiveStreamClosed(nil) | ||
} | ||
|
||
for channel in self._pendingStreams.values { | ||
channel.receiveStreamClosed(nil) | ||
} | ||
|
||
self.streamChannelContinuation?.finish(throwing: error) | ||
} | ||
|
||
internal func propagateHandlerRemoved() { | ||
for channel in self.streams.values { | ||
channel.receiveStreamClosed(nil) | ||
} | ||
|
||
for channel in self._pendingStreams.values { | ||
channel.receiveStreamClosed(nil) | ||
} | ||
|
||
self.streamChannelContinuation?.finish() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be closing the streams in these cases, we should just finish the continuation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For errorCaught
I think you're right (although I'm not sure what it would mean if there was a connection error fired down the pipeline but we keep the streams opened?); however if the handler was removed, wouldn't it make sense to close the streams? Is there anything we can do with them if the connection has died?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the HTTP2StreamMultiplexer
, handler removed calls clearDidReadChannels
in the common (i.e. this) multiplexer:
swift-nio-http2/Sources/NIOHTTP2/HTTP2StreamMultiplexer.swift
Lines 43 to 46 in 91136a6
public func handlerRemoved(context: ChannelHandlerContext) { | |
self.context = nil | |
self.commonStreamMultiplexer.clearDidReadChannels() | |
} |
I don't think we should have divergent behaviour between the two. When we reach handlerRemoved
the streams will have already been closed.
For error caught, the HTTP2StreamMultiplexer
only propagates stream errors to the child channels, they then get to decide how to act on those errors. Any connection level errors aren't propagated to streams and go down the channel pipeline and another handler decides how to act on it (usually by closing the connection, which will result in the streams being closed), but we should avoid short circuiting that because not all errors result in the connection being closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks George, that's clear. I'll make the change.
9e1501a
to
f7be51f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nit, but looks good otherwise, thanks @gjcairo
Tests/NIOHTTP2Tests/SimpleClientServerInlineStreamMultiplexerTests.swift
Outdated
Show resolved
Hide resolved
…ests.swift Co-authored-by: George Barnett <gbarnett@apple.com>
Motivation
Currently, the multiplexer's inbound streams stream is finished only when the channel becomes inactive.
There are some scenarios in which the channel may be closed before it has a chance to become active, and the stream will never be finished. This can cause any users iterating over the stream to hang.
Modifications
This PR finishes the inbound streams stream when a connection error is fired, and when the handler is removed.
Result
Fewer bugs.