Skip to content

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

Merged
mox692 merged 3 commits intotokio-rs:masterfrom
mox692:mox692/add_future_size_check_more
Jul 18, 2024
Merged

task: add size check for user-supplied future#6692
mox692 merged 3 commits intotokio-rs:masterfrom
mox692:mox692/add_future_size_check_more

Conversation

@mox692
Copy link
Copy Markdown
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
Copy Markdown
Member

@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
Copy Markdown
Member

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