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

io: add budgeting to tokio::runtime::io::registration::async_io #6221

Merged
merged 5 commits into from
Dec 17, 2023

Conversation

Noah-Kennedy
Copy link
Contributor

@Noah-Kennedy Noah-Kennedy commented Dec 16, 2023

Fixes #5946.
Fixes #4782.

This change adds budgeting to most of the remaining unbudgeted IO operations which can complete instantly, including datagram send/recv operations and listener socket accepts.

This is particularly significant for scenarios in which resource limits are hit, as it can be common for things like listener tasks to spin when receiving errors and just log them, busy looping worker threads which might otherwise be handling existing connections and closing them.

This can also sometimes lead to complex failure scenarios within datagram systems experiencing resource exhaustion.

@Noah-Kennedy Noah-Kennedy self-assigned this Dec 16, 2023
@Noah-Kennedy Noah-Kennedy force-pushed the noah/budget-fix branch 2 times, most recently from 05775ab to 4c8b4b5 Compare December 16, 2023 19:37
@Darksonn Darksonn added A-tokio Area: The main tokio crate M-net Module: tokio/net M-coop Module: tokio/coop labels Dec 16, 2023
@Noah-Kennedy
Copy link
Contributor Author

Note: this is being backported, so do not merge.

I will merge it manually on the command line.

Comment on lines 222 to 231
let coop = crate::future::poll_fn(crate::runtime::coop::poll_proceed).await;

match f() {
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
self.clear_readiness(event);
}
x => return x,
x => {
coop.made_progress();

return x;
Copy link
Contributor

Choose a reason for hiding this comment

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

This affects only things that use async_io. I believe that we discussed a different fix on one of the issues, which is the following:

  • Polling for readiness returns Pending on missing coop budget, but does not consume budget.
  • IO operations, even non-async ones, consume a budget, but do not check it.

With the above change, async_io would get the right behavior automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This feels like the correct way to do the accounting, but I'm worried it might lead to more significant changes in behavior than we may intend (e.g many users might be expecting try_ ops to not touch the buget).

Perhaps we can use this current method for the patch releases, and then the other method for the next minor version release we do?

Copy link
Contributor

Choose a reason for hiding this comment

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

That works for me.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

This version is ok for the backports to LTSs.

Fixes #5946.
Fixes #4782.

This change adds budgeting to most of the remaining unbudgeted IO operations which can complete instantly, including datagram send/recv operations and listener socket accepts.

This is particularly significant for scenarios in which resource limits are hit, as it can be common for things like listener tasks to spin when receiving errors and just log them, busy looping worker threads which might otherwise be handling existing connections and closing them.

This can also sometimes lead to complex failure scenarios within datagram systems experiencing resource exhaustion.
@Noah-Kennedy Noah-Kennedy changed the base branch from master to tokio-1.25.x December 16, 2023 22:04
@github-actions github-actions bot added the R-loom Run loom tests on this PR label Dec 16, 2023
@Noah-Kennedy Noah-Kennedy enabled auto-merge (squash) December 17, 2023 22:31
@Noah-Kennedy Noah-Kennedy merged commit ab7313f into tokio-1.25.x Dec 17, 2023
49 checks passed
@Noah-Kennedy Noah-Kennedy deleted the noah/budget-fix branch December 17, 2023 22:34
Noah-Kennedy pushed a commit that referenced this pull request Dec 17, 2023
# 1.25.3 (December 17thm 2023)

### Fixed
- io: add budgeting to tokio::runtime::io::registration::async_io ([#6221])

[#6221]: #6221
Noah-Kennedy pushed a commit that referenced this pull request Dec 17, 2023
# 1.25.3 (December 17thm 2023)

### Fixed
- io: add budgeting to tokio::runtime::io::registration::async_io ([#6221])

[#6221]: #6221
Noah-Kennedy pushed a commit that referenced this pull request Dec 17, 2023
# 1.25.3 (December 17thm 2023)

### Fixed
- io: add budgeting to tokio::runtime::io::registration::async_io ([#6221])

[#6221]: #6221
Noah-Kennedy added a commit that referenced this pull request Dec 19, 2023
# 1.25.3 (December 17thm 2023)

### Fixed
- io: add budgeting to `tokio::runtime::io::registration::async_io` ([#6221])

[#6221]: #6221
@@ -0,0 +1,77 @@
#![warn(rust_2018_idioms)]

Choose a reason for hiding this comment

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

Should this file be called core_budger.rs? Should it not be core_budget.rs (notice the "t" at the end and not "r")?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, nice catch. Do you want to submit a PR that fixes it?

Choose a reason for hiding this comment

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

Admittedly not, my apologies. Just a drive-by observation as I am clocking out of work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

once again, the keyboard on the new laptop has bested me

kodiakhq bot pushed a commit to pdylanross/fatigue that referenced this pull request Dec 20, 2023
Bumps tokio from 1.35.0 to 1.35.1.

Release notes
Sourced from tokio's releases.

Tokio v1.35.1
1.35.1 (December 19, 2023)
This is a forward part of a change that was backported to 1.25.3.
Fixed

io: add budgeting to tokio::runtime::io::registration::async_io (#6221)

#6221: tokio-rs/tokio#6221



Commits

46ff363 chore: prepare Tokio v1.35.1 (#6230)
0a1695e Merge 'tokio-1.32.1' into 'tokio-1.35.x' (#6229)
c4f0178 chore: prepare Tokio v1.32.1 (#6228)
22b3a65 Merge 'tokio-1.25.3' into 'tokio-1.32.x' (#6227)
0d36233 chore: release v1.25.3 (#6223)
ab7313f io: add budgeting to tokio::runtime::io::registration::async_io (#6221)
See full diff in compare view




Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot merge will merge this PR after your CI passes on it
@dependabot squash and merge will squash and merge this PR after your CI passes on it
@dependabot cancel merge will cancel a previously requested merge and block automerging
@dependabot reopen will reopen this PR if it is closed
@dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-coop Module: tokio/coop M-net Module: tokio/net R-loom Run loom tests on this PR
Projects
None yet
3 participants