Skip to content
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

Fix parent channel read() call on HTTP2StreamChannel initialization causing incorrect order of inbound HTTP2Frames #413

Merged
merged 1 commit into from Jul 28, 2023

Conversation

qusc
Copy link
Contributor

@qusc qusc commented Jul 26, 2023

Motivation:

Make sure the order of HTTP2Frames that are fired through the pipeline of a HTTP2StreamChannel by HTTP2CommonInboundStreamMultiplexer is correct when a read() call on the parent channel synchronously causes further frames to be processed.

Modifications:

Reorder calls in HTTP2CommonInboundStreamMultiplexer.receivedFrame(frame:context:multiplexer) so that initial header frame is buffered and processed first.

Result:

Resolves #410 and makes newly added test case HTTP2StreamMultiplexerTests.testMultiplexerFiresInitialFramesInCorrectOrder() pass.

Comment on lines 112 to 116
channel.configureInboundStream(initializer: self.inboundStreamStateInitializer)
channel.receiveInboundFrame(frame)
channel.configureInboundStream(initializer: self.inboundStreamStateInitializer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite subtle. Can we add a comment here that this order is important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely; done

@Lukasa Lukasa added the patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) label Jul 27, 2023
@Lukasa
Copy link
Contributor

Lukasa commented Jul 27, 2023

@swift-server-bot test this please

@Lukasa
Copy link
Contributor

Lukasa commented Jul 27, 2023

@swift-server-bot test this please

@Lukasa
Copy link
Contributor

Lukasa commented Jul 27, 2023

Locally your test crashes for me:

Test Case '-[NIOHTTP2Tests.HTTP2StreamMultiplexerTests testMultiplexerFiresInitialFramesInCorrectOrder]' started.
NIOCore/NIOAny.swift:200: Fatal error: tried to decode as type HTTP2Frame but found FramePayload with contents other(NIOHTTP2.HTTP2Frame.FramePayload.headers(NIOHTTP2.HTTP2Frame.FramePayload.Headers(headers: [], priorityData: nil, endStream: false, _paddingBytes: nil)))

@qusc
Copy link
Contributor Author

qusc commented Jul 27, 2023

Locally your test crashes for me:

Test Case '-[NIOHTTP2Tests.HTTP2StreamMultiplexerTests testMultiplexerFiresInitialFramesInCorrectOrder]' started.
NIOCore/NIOAny.swift:200: Fatal error: tried to decode as type HTTP2Frame but found FramePayload with contents other(NIOHTTP2.HTTP2Frame.FramePayload.headers(NIOHTTP2.HTTP2Frame.FramePayload.Headers(headers: [], priorityData: nil, endStream: false, _paddingBytes: nil)))

@Lukasa looking into this...

@qusc
Copy link
Contributor Author

qusc commented Jul 27, 2023

@Lukasa Apparently caused by the switch to the non-deprecated init of HTTP2StreamMultiplexer. That implicitly switches the elements being sent down the pipeline to HTTP2Frame.Payload to exclude the stream id? But the InboundOut type of HTTP2StreamMultiplexer is technically still HTTP2Frame?
Edit: this is about the type of elements fired on the child channel, I see...

…on causing incorrect order of inbound `HTTP2Frame`s

Motivation:

Make sure the order of `HTTP2Frame`s that are fired through the pipeline of a `HTTP2StreamChannel` by `HTTP2CommonInboundStreamMultiplexer` is correct when a `read()` call on the parent channel synchronously causes further frames to be processed.

Modifications:

Reorder calls in `HTTP2CommonInboundStreamMultiplexer.receivedFrame(frame:context:multiplexer)` so that initial header frame is buffered and processed first.

Result:

Resolves apple#410 and makes newly added test case `HTTP2StreamMultiplexerTests.testMultiplexerFiresInitialFramesInCorrectOrder()` pass.
@qusc
Copy link
Contributor Author

qusc commented Jul 27, 2023

@swift-server-bot test this please if I'm allowed to trigger that

@Lukasa
Copy link
Contributor

Lukasa commented Jul 27, 2023

@swift-server-bot add to allowlist

@qusc qusc requested a review from Lukasa July 27, 2023 14:24
@Lukasa Lukasa merged commit 493897c into apple:main Jul 28, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race condition causes header frame to be fired on HTTP2StreamChannel AFTER first data frame(s)
3 participants