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

return join handle when spawning a tokio task #1351

Merged
merged 1 commit into from Nov 15, 2022

Conversation

Simon-Laux
Copy link
Contributor

@Simon-Laux Simon-Laux commented Oct 25, 2022

This pr makes the spawn function return the join handle so it can be safely aborted when droping the object it is
spawned for.

Without this I need to run the future in a different tokio runtime instance to avoid a segfault:
deltachat/napi-jsonrpc@de56163

More info on the issue: deltachat/napi-jsonrpc#2

Basically I have an event receiving loop that is spawned when creating an account manager, but without this pr I'm not able to shutdown/abort the event loop safely resulting in a segfault when Nodejs garbage collects the object.

we need this to be able to safely drop an struct,
that makes use of an async task.
the drop function needs to be able to call `.abort()`
on the join handle to avoid memory corruption and undefined bahviour.
@Brooooooklyn Brooooooklyn merged commit 035def0 into napi-rs:main Nov 15, 2022
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.

None yet

2 participants