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 bug where client ignores HEADERS frames on open stream when locally quiescing #445

Merged
merged 6 commits into from
Jul 18, 2024

Conversation

aryan-25
Copy link
Contributor

@aryan-25 aryan-25 commented Jul 4, 2024

Motivation:

Currently, HEADERS frames are ignored by the client on a client-initiated stream after the client sends a GOAWAY.

As per Section 6.8 (GOAWAY) in RFC 9113:
"Once the GOAWAY is sent, the sender will ignore frames sent on streams initiated by the receiver if the stream has an identifier higher than the included last stream identifier."

In this case, the client (sender) should not ignore the HEADERS frame as the stream is initiated by the client, not the receiver.

Modifications:

Fixed the condition in the receiveHeaders function (given LocallyQuiescingState) in ReceivingHeadersState.swift to work for both the client and server roles -- before this change, the condition is only correct when self.role == ConnectionRole.server.

Result:

HEADERS frames are not ignored by the client on a client-initiated stream when locally quiescing.

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 looks great, I only style/naming comments.

Tests/NIOHTTP2Tests/ConnectionStateMachineTests.swift Outdated Show resolved Hide resolved
Comment on lines 64 to 75
extension HTTP2ConnectionStateMachine.ConnectionRole {
/// Obtain the inverse role to self
/// - Returns: The inverse role
fileprivate func inverse() -> Self {
switch self {
case .server:
return .client
case .client:
return .server
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we move this to where ConnectionRole is defined?

@glbrntt
Copy link
Contributor

glbrntt commented Jul 4, 2024

@swift-server-bot add to allowlist

@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Jul 4, 2024
@@ -17,7 +17,7 @@ import NIOHPACK
/// can validly accept headers.
///
/// This protocol should only be conformed to by states for the HTTP/2 connection state machine.
protocol ReceivingHeadersState: HasFlowControlWindows, HasLocalExtendedConnectSettings, HasRemoteExtendedConnectSettings {
protocol ReceivingHeadersState: HasFlowControlWindows, HasLocalExtendedConnectSettings, HasRemoteExtendedConnectSettings, ConnectionStateWithRole {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the protocol constraint here at all? We already have the role.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, ConnectionStateWithRole has a member peerRole which is being used as part of the fix:

image

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.

Great, I'm happy if George is happy.

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.

Awesome, thanks @aryan-25!

@glbrntt glbrntt enabled auto-merge (squash) July 18, 2024 13:47
@glbrntt glbrntt merged commit 35b0b8f into apple:main Jul 18, 2024
6 of 7 checks passed
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.

3 participants