Skip to content

Crash fix: HTTP2 can handle requests are cancelled #555

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

Merged

Conversation

fabianfett
Copy link
Member

@fabianfett fabianfett commented Feb 9, 2022

Motivation

If a already cancelled request is scheduled on an existing HTTP/2 connection we currently run into a crash. This only happens if the request is scheduled on the same EventLoop as the HTTP/2 connection.

Changes

  • Make the HTTPRequestStateMachine resilient to failures before request start.

Result

  • A crash less.

@fabianfett fabianfett requested review from weissi and glbrntt February 9, 2022 19:53
Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

awesome, thank you!

@fabianfett fabianfett added the 🔨 semver/patch No public API change. label Feb 9, 2022
@fabianfett fabianfett requested a review from dnadoba February 10, 2022 08:17
Copy link
Collaborator

@dnadoba dnadoba left a comment

Choose a reason for hiding this comment

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

One nit, otherwise nice fix! Thanks!

XCTAssertNoThrow(request = try HTTPClient.Request(url: "https://localhost:\(bin.port)"))

// just to establish an existing connection
XCTAssertNoThrow(try client.execute(request: XCTUnwrap(request)).wait())
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh, nice use of XCTUnwrap inside a throwable auto closure!

@@ -193,11 +193,15 @@ final class HTTP2ClientRequestHandler: ChannelDuplexHandler {
case .forwardResponseBodyParts(let parts):
self.request!.receiveResponseBodyParts(parts)

case .failRequest(let error, let finalAction):
case .failRequest(let error, _):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still use finalAction elsewhere or can we remove it from the enum?

Copy link
Member Author

Choose a reason for hiding this comment

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

We use it in the HTTP1ConnectionStateMachine.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the reason for the comment starting in line 200.

Copy link
Collaborator

@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.

LGTM!

@dnadoba
Copy link
Collaborator

dnadoba commented Feb 10, 2022

@swift-server-bot test this please

@fabianfett
Copy link
Member Author

5.6 and nightly failing because of Sendable requirements.

@fabianfett fabianfett merged commit 5844a6b into swift-server:main Feb 10, 2022
@fabianfett fabianfett deleted the ff-h2-crash-cancelled-request branch February 10, 2022 09:42
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