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

task: add size check for user-supplied future #6692

Merged
merged 3 commits into from
Jul 18, 2024

Conversation

mox692
Copy link
Member

@mox692 mox692 commented Jul 17, 2024

Closes #6673.

Like #4009, this PR adds a size check logic for public apis that accepts user-provided futures so that large futures are not repeatedly passed to the function and exhaust the stack.

Also, this extracts commonly used constant.

@mox692 mox692 added A-tokio Area: The main tokio crate M-task Module: tokio/task labels Jul 17, 2024
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.

It's a bit hard for me to tell whether you've added the check in all of the right places, but looks reasonable.

Comment on lines 388 to 390
/// Boundary value to prevent stack overflow caused by a large-sized
/// Future being placed in the stack.
pub(crate) const MAX_FUTURE_SIZE: usize = 2048;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not really a maximum for the future size.

Suggested change
/// Boundary value to prevent stack overflow caused by a large-sized
/// Future being placed in the stack.
pub(crate) const MAX_FUTURE_SIZE: usize = 2048;
/// Boundary value to prevent stack overflow caused by a large-sized
/// Future being placed in the stack.
pub(crate) const BOX_FUTURE_THRESHOLD: usize = 2048;

@mox692 mox692 enabled auto-merge (squash) July 18, 2024 11:42
@mox692 mox692 merged commit da17c61 into tokio-rs:master Jul 18, 2024
77 checks passed
This was referenced Jul 22, 2024
@mox692 mox692 deleted the mox692/add_future_size_check_more branch July 24, 2024 12:52
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-task Module: tokio/task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Box futures passed to block_on in debug mode
3 participants