Skip to content

Crash fix: HTTP2ClientRequestHandler can deal with failing writes #558

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

Conversation

fabianfett
Copy link
Member

Motivation

AHC can currently not deal with direct failures when writing requests.

Changes

  • Make HTTP2ClientRequestHandler resilient to failing writes

Result

Less crashes in AHC HTTP/2.

@fabianfett fabianfett requested review from weissi and glbrntt February 10, 2022 16:23
@fabianfett fabianfett added the 🔨 semver/patch No public API change. label Feb 10, 2022
@fabianfett fabianfett force-pushed the ff-crash-in-http-client-request-handler branch from 308fdd0 to ed98b97 Compare February 10, 2022 16:24
// The above response head forward might lead the request to mark itself as
// cancelled, which in turn might pop the request of the handler. For this reason we
// must check if the request is still present here.
request.pauseRequestBodyStream()
Copy link
Contributor

@karwa karwa Feb 10, 2022

Choose a reason for hiding this comment

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

This all seems very fragile. Each action is very tightly coupled to the state machine to check its own internal state, and some of these methods require non-local reasoning (e.g. calling a method on a request which reaches up and nils that request variable in its owner object).

It's perhaps worth questioning: with the tight coupling, is it worth dispatching all of these operations with a single enum? Perhaps each case should be an individual method, invoked directly with the unwrapped request value. The cancellation stuff is also not ideal but I don't have a concrete suggestion at this time.

Certainly the crash fix is important and I'm not suggesting it be delayed for refactoring, but it's maybe worth making a note to take another look at it later, and see if it can be made more robust.

Copy link
Member Author

@fabianfett fabianfett Feb 10, 2022

Choose a reason for hiding this comment

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

Very much agree! I guess that's the big learning from this state machine.

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.

Thank you

@fabianfett fabianfett merged commit 71af9c7 into swift-server:main Feb 22, 2022
@fabianfett fabianfett deleted the ff-crash-in-http-client-request-handler branch February 22, 2022 12:59
fabianfett added a commit to fabianfett/async-http-client that referenced this pull request Apr 11, 2022
Same fix for HTTP/1 that landed for HTTP/2 in swift-server#558.

### Motivation

`HTTP1ClientChannelHandler` currently does not tolerate immediate write errors.

### Changes

Make `HTTP1ClientChannelHandler` resilient to failing writes.

### Result

Less crashes in AHC HTTP/1.
fabianfett added a commit that referenced this pull request Apr 11, 2022
Same fix for HTTP/1 that landed for HTTP/2 in #558.

### Motivation

`HTTP1ClientChannelHandler` currently does not tolerate immediate write errors.

### Changes

Make `HTTP1ClientChannelHandler` resilient to failing writes.

### Result

Less crashes in AHC HTTP/1.
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