Skip to content

Better backpressure management. #352

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
merged 1 commit into from
Mar 30, 2021

Conversation

Lukasa
Copy link
Collaborator

@Lukasa Lukasa commented Mar 29, 2021

Motivation:

Users of the HTTPClientResponseDelegate expect that the event loop
futures returned from didReceiveHead and didReceiveBodyPart can be used
to exert backpressure. To be fair to them, they somewhat can. However,
the TaskHandler has a bit of a misunderstanding about how NIO
backpressure works, and does not correctly manage the buffer of inbound
data.

The result of this misunderstanding is that multiple calls to
didReceiveBodyPart and didReceiveHead can be outstanding at once. This
would likely lead to severe bugs in most delegates, as they do not
expect it.

We should make things work the way delegate implementers believe it
works.

Modifications:

  • Added a buffer to the TaskHandler to avoid delivering data that the
    delegate is not ready for.
  • Added a new "pending close" state that keeps track of a state where
    the TaskHandler has received .end but not yet delivered it to the
    delegate. This allows better error management.
  • Added some more tests.
  • Documented our backpressure commitments.

Result:

Better respect for backpressure.

Resolves #348

@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Mar 29, 2021
@Lukasa Lukasa requested review from artemredkin and weissi March 29, 2021 08:07
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! lgtm

@Lukasa Lukasa force-pushed the cb-better-backpressure branch 2 times, most recently from 98781fd to ab657b9 Compare March 30, 2021 10:18
Motivation:

Users of the HTTPClientResponseDelegate expect that the event loop
futures returned from didReceiveHead and didReceiveBodyPart can be used
to exert backpressure. To be fair to them, they somewhat can. However,
the TaskHandler has a bit of a misunderstanding about how NIO
backpressure works, and does not correctly manage the buffer of inbound
data.

The result of this misunderstanding is that multiple calls to
didReceiveBodyPart and didReceiveHead can be outstanding at once. This
would likely lead to severe bugs in most delegates, as they do not
expect it.

We should make things work the way delegate implementers believe it
works.

Modifications:

- Added a buffer to the TaskHandler to avoid delivering data that the
   delegate is not ready for.
- Added a new "pending close" state that keeps track of a state where
   the TaskHandler has received .end but not yet delivered it to the
   delegate. This allows better error management.
- Added some more tests.
- Documented our backpressure commitments.

Result:

Better respect for backpressure.

Resolves swift-server#348
@Lukasa Lukasa force-pushed the cb-better-backpressure branch from ab657b9 to b091506 Compare March 30, 2021 10:26
@Lukasa Lukasa merged commit e4fded7 into swift-server:main Mar 30, 2021
@Lukasa Lukasa deleted the cb-better-backpressure branch March 30, 2021 10:39
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.

FileDownloadDelegate can issue out-of-order writes
3 participants