Skip to content

Conversation

stepancheg
Copy link
Contributor

Motivation

Some code is written incorrectly: it spawns a task, but does not track whether task is still needed, e.g. request was not dropped. AbortOnDropHandle helps with this problem, but it is a bit unergonomic.

Solution

Add AbortOnDropHandle::spawn shortcut.

ADD-SP
ADD-SP previously requested changes Aug 29, 2025
Copy link
Member

@ADD-SP ADD-SP left a comment

Choose a reason for hiding this comment

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

This new interface will surprise downstream, and people will be confused by it because this isn't what AbortOnDropHandle is supposed to do.

Would you mind elaborating on your motivation? it's difficult for me to grasp the current motivation in the PR description.

  • What are the challenges without this feature?
  • How does this feature solve these challanges?

@ADD-SP ADD-SP added A-tokio-util Area: The tokio-util crate M-task Module: tokio/task C-feature-request Category: A feature request. S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. labels Aug 29, 2025
@stepancheg
Copy link
Contributor Author

this isn't what AbortOnDropHandle is supposed to do.

I don't understand. What it is supposed to do?

What are the challenges without this feature?

99% of tasks I create needs abort on drop (and I guess, in many cases, other people should be doing that too). So shortcut this this common operation is desirable.

Shortcut can be member function of AbortOnDropHandle, or could be standalone function like spawn_abort_on_drop.

How does this feature solve these challenges?

This PR makes this common pattern more ergonomic.

@ADD-SP
Copy link
Member

ADD-SP commented Aug 29, 2025

Shortcut can be member function of AbortOnDropHandle, or could be standalone function like spawn_abort_on_drop.

For existing interface, downstream have to do this.

let hdl = AbortOnDropHandle::new(tokio::spawn(...));

And you want a shortcut like this, is my understanding correct?

let hdl = AbortOnDropHandle::spawn(...);

If so, would you mind adding this kind of example to the PR description? I believe this can help reviewers to get the motivation in 10 seconds.

@stepancheg stepancheg force-pushed the abort-on-drop-handle-spawn branch 2 times, most recently from 83a4f88 to b2514fd Compare August 31, 2025 00:01
@stepancheg
Copy link
Contributor Author

Added an example.

@stepancheg stepancheg requested a review from ADD-SP August 31, 2025 00:02
I believe this is 99% of `AbortOnDropHandle` use cases.
@stepancheg stepancheg force-pushed the abort-on-drop-handle-spawn branch from b2514fd to bec2347 Compare August 31, 2025 00:04
@ADD-SP ADD-SP dismissed their stale review August 31, 2025 02:20

Now I understand the motivation.

Copy link
Member

@ADD-SP ADD-SP left a comment

Choose a reason for hiding this comment

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

I searched the history of AbortOnDropHandle, there was a short discussion about AbortOnDropHandle::spawn, see #6786 (comment).

Initially, there was a AbortOnDropHandle::spawn, but it was removed before merging.

Shortcut can be member function of AbortOnDropHandle, or could be standalone function like spawn_abort_on_drop.

A standalone function spawn_abort_on_drop was also considered, but the AbortOnDropHandle::new was win.

I think having a shortcut is beneficial, but we need a approach which looks better than spawn_abort_on_drop.

@ADD-SP
Copy link
Member

ADD-SP commented Sep 23, 2025

Thanks for your PR! I closed this PR as currently we don't have a better approach. Feel free to re-open this PR or open a new once once you have a better approach.

@ADD-SP ADD-SP closed this Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate C-feature-request Category: A feature request. M-task Module: tokio/task S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants