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

Accept PING frames even when fully quiesced #455

Merged
merged 5 commits into from
Aug 30, 2024

Conversation

clintonpi
Copy link
Contributor

@clintonpi clintonpi commented Aug 21, 2024

Motivation:

When the connection is fully quiesced, an endpoint responds with a connection error when it receives or tries to respond to a PING frame. This behaviour is unnecessary.

Modifications:

  • Adjust HTTP2ConnectionStateMachine to successfully receive and send PING frames even when the connection is fully quiesced.

Result:

When the connection is fully quiesced, an endpoint will treat receipt and sending of a PING frame as it would when the connection is active.

Motivation:

When the connection is fully quiesced, an endpoint responds with a connection error when it receives a PING frame. This behaviour is unnecessary.

Modifications:

- Adjust `HTTP2ConnectionStateMachine` to accept PING frames even when the connection is fully quiesced.

Result:

When the connection is fully quiesced, an endpoint will treat the receipt of a PING frame as it would when the connection is active.
@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Aug 21, 2024
Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

This generally looks good, but I would like us to add an actual E2E test that proves that we can send the PING ACK as well.

@clintonpi
Copy link
Contributor Author

Oops. Yes, of course.

- Add E2E test.
- Allow sending PINGs on a fully quiesced connection.
@clintonpi clintonpi requested a review from Lukasa August 23, 2024 08:38
Comment on lines 868 to 869
@available(*, deprecated, message: "Deprecated so deprecated functionality can be tested without warnings")
func testSuccessfullyReceiveAndSendPingEvenWhenConnectionIsFullyQuiesced() throws {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid you've fallen into one of the many deprecated-API traps 🪤

This whole test class is deprecated because it's testing deprecated APIs. There's an equivalent set of tests in SimpleClientServerInlineStreamMultiplexerTests where this test should live. I think in this instance your test should just work without modifications.


An aside on the deprecated APIs. The original APIs for multiplexing created child channels for streams where you'd read and write HTTP2Frames.

Each HTTP2Frame holds a stream ID and its payload (headers, data etc.) However, when you open a stream the connection state machine wouldn't know about the stream until you did the first write on that stream.

This means that a client could create stream 1 and then stream 3 but write on stream 3 first. A subsequent write on stream 1 would be a protocol violation (new streams must have higher IDs than previously created streams).

To fix this we added new stream creation APIs where the child channels operate on HTTP2Frame.FramePayloads and only when they do their first write do they get assigned a stream ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that makes sense. Thanks.

Comment on lines 875 to 878
let goAwayFrame = HTTP2Frame(streamID: .rootStream, payload: .goAway(lastStreamID: .rootStream, errorCode: .noError, opaqueData: nil))

// Fully quiesce the connection on the server.
serverChannel.writeAndFlush(goAwayFrame, promise: nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

The go away frame is strongly coupled with this write so it makes sense to group it with it and the comment.

Suggested change
let goAwayFrame = HTTP2Frame(streamID: .rootStream, payload: .goAway(lastStreamID: .rootStream, errorCode: .noError, opaqueData: nil))
// Fully quiesce the connection on the server.
serverChannel.writeAndFlush(goAwayFrame, promise: nil)
// Fully quiesce the connection on the server.
let goAwayFrame = HTTP2Frame(streamID: .rootStream, payload: .goAway(lastStreamID: .rootStream, errorCode: .noError, opaqueData: nil))
serverChannel.writeAndFlush(goAwayFrame, promise: nil)

Comment on lines 880 to 883
let pingFrame = HTTP2Frame(streamID: .rootStream, payload: .ping(HTTP2PingData(), ack: false))

// Send PING frame to the server.
clientChannel.writeAndFlush(pingFrame, promise: nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

same here:

Suggested change
let pingFrame = HTTP2Frame(streamID: .rootStream, payload: .ping(HTTP2PingData(), ack: false))
// Send PING frame to the server.
clientChannel.writeAndFlush(pingFrame, promise: nil)
// Send PING frame to the server.
let pingFrame = HTTP2Frame(streamID: .rootStream, payload: .ping(HTTP2PingData(), ack: false))
clientChannel.writeAndFlush(pingFrame, promise: nil)

Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

This LGTM, thanks @clintonpi!

@Lukasa
Copy link
Contributor

Lukasa commented Aug 27, 2024

@swift-server-bot test this please

@gjcairo gjcairo enabled auto-merge (squash) August 30, 2024 10:40
@gjcairo gjcairo merged commit 9f6d865 into apple:main Aug 30, 2024
6 of 7 checks passed
@clintonpi clintonpi deleted the accept-pings-when-fully-quiesced branch August 30, 2024 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants