Correctly notify StreamMultiplexer of SETTINGS changes. (#67)

Motivation:

The StreamMultiplexer and StreamChannels are responsible for sending
WINDOW_UPDATE frames, but they were never told if the user changed the
value of SETTINGS_INITIAL_WINDOW_SIZE. They should be.

Modifications:

- Send user events when SETTINGS_INITIAL_WINDOW_SIZE changes.
- Use those window events to change the target window size in
    HTTP2StreamChannel.
- Keep track of the last stream window size we knew.

Result:

Less chance of flow control mess.
This commit is contained in:
Cory Benfield authored and GitHub committed 2019-03-15 17:37:00 +00:00
1 parent 1138881931
commit 55daa4cd4e
9 files changed
+155 -8

No files matched your search

@@ -31,7 +31,7 @@ public final class HTTP2StreamMultiplexer: ChannelInboundHandler, ChannelOutboun
private let inboundStreamStateInitializer: ((Channel, HTTP2StreamID) -> EventLoopFuture<Void>)?
private let channel: Channel
private var nextOutboundStreamID: HTTP2StreamID
private let connectionFlowControlManager: InboundWindowManager
private var connectionFlowControlManager: InboundWindowManager
public func handlerAdded(context: ChannelHandlerContext) {
// We now need to check that we're on the same event loop as the one we were originally given.
@@ -61,7 +61,7 @@ public final class HTTP2StreamMultiplexer: ChannelInboundHandler, ChannelOutboun
let channel = HTTP2StreamChannel(allocator: self.channel.allocator,
parent: self.channel,
streamID: streamID,
targetWindowSize: 65535, // TODO: make configurable
targetWindowSize: 65535,
initiatedRemotely: true)
self.streams[streamID] = channel
channel.configure(initializer: self.inboundStreamStateInitializer)
@@ -106,6 +106,13 @@ public final class HTTP2StreamMultiplexer: ChannelInboundHandler, ChannelOutboun
if let channel = self.streams[evt.streamID], let windowSize = evt.inboundWindowSize {
channel.receiveWindowUpdatedEvent(windowSize)
}
case let evt as NIOHTTP2BulkStreamWindowChangeEvent:
// Here we need to pull the channels out so we aren't holding the streams dict mutably. This is because it
// will trigger an overlapping access violation if we do.
let channels = self.streams.values
for channel in channels {
channel.initialWindowSizeChanged(delta: evt.delta)
}
default:
break
}