Skip to content

fix(wasm): don't kill task on drop #4572

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
Apr 8, 2025

Conversation

maan2003
Copy link
Contributor

makes behavior similar to tokio::spawn otherwise spawned tasks immediately die if join handles are not saved somewhere

@maan2003 maan2003 requested a review from a team as a code owner January 22, 2025 11:23
@maan2003 maan2003 requested review from jmartinesp and removed request for a team January 22, 2025 11:23
@maan2003
Copy link
Contributor Author

cc @jplatte

Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 85.37%. Comparing base (2657eb7) to head (3818d1c).
Report is 793 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk-common/src/executor.rs 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4572      +/-   ##
==========================================
- Coverage   85.39%   85.37%   -0.02%     
==========================================
  Files         286      286              
  Lines       32229    32235       +6     
==========================================
  Hits        27522    27522              
- Misses       4707     4713       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Hywan Hywan requested review from Hywan and removed request for jmartinesp January 27, 2025 16:21
#[cfg(target_arch = "wasm32")]
impl<T> Drop for JoinHandle<T> {
fn drop(&mut self) {
// don't abort the spawned future
Copy link
Member

Choose a reason for hiding this comment

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

This comment must be elaborated to explain why we don't abort the future when the join handle is dropped:

  • Why?
  • Does it match the Tokio's behaviour?

Thanks.

Copy link
Collaborator

@jplatte jplatte Apr 5, 2025

Choose a reason for hiding this comment

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

Yes, it matches tokio's behavior and I'm pretty sure that's exactly the reason for changing the behavior here. I think we discussed it on Matrix previously that a cancel-on-drop JoinHandle might make more sense for the SDK, but then you would have to

  • wrap the tokio JoinHandle for non-wasm
  • update all the existing cases where JoinHandles are dropped prematurely to store the handle somewhere, or call some detach method on it

That's a lot harder. I think you should accept this PR that fixes the existing inconsistency (which leads to buggy behavior), and evaluate the different JoinHandle semantics afterwards.

@Hywan
Copy link
Member

Hywan commented Jan 28, 2025

Thanks for your contribution :-).

It would be nice if you could address my comment, and if tests could be added. This is an important change.

@maan2003
Copy link
Contributor Author

maan2003 commented Apr 5, 2025

what do you think about using https://docs.rs/n0-future/latest/n0_future/ instead of custom stuff

@Hywan Hywan merged commit 39212db into matrix-org:main Apr 8, 2025
40 checks passed
@Hywan
Copy link
Member

Hywan commented Apr 8, 2025

Let's go with the current proposal. I'm not in favor of adding more deps, we already have too much of them.

bnjbvr pushed a commit that referenced this pull request Apr 23, 2025
…kio::spawn` to make it wasm compatible. (#4959)

This PR is a revived version of:
#4707 since it is now
possible to easily add wasm support thanks to:
#4572

Using the `executer::spawn` will select `tokio::spawn` or
`wasm_bindgen_futures::spawn_local` based on what platform we are on.

~~They behave differently in that `tokio` actually starts the async
block inside the spawn but the wasm `spawn` wrapper will only start the
part that is not inside the `async` block and the join handle needs to
be awaited for it to work.~~

This has now changed with:
#4572.
Now they behave the same and this PR becomes a very simple change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants