alexcrichton opened PR #14266 from alexcrichton:synchronize-more-tasks to bytecodealliance:main:
This commit fixes a test failure I'm running into in wasi-libc development where spawned tasks for wasip2 are keeping objects alive in a race condition where sometimes the task is torn down and sometimes it's not. Specifically wasip2 is built on wasip3-style primitives for UDP/TCP which means that futures are used, and if futures aren't immediately ready they're resolved in a spawned Tokio task. This spawned task can interact with UDP, for example, where exclusivity of a UDP socket is tested via
Arc::get_mutwhich will nondeterministically return true or false depending if a previously spawned task has exited or not. In wasi-libc this means that reconnecting a UDP socket sometimes fails and sometimes passes because the background task may or may not have exited.Here this is resolved by making the
dropmethods async and then hooking into the preexistingcancelmethod which aborts the task and then waits on the result. This synchronizes with the task to ensure that the state of the socket is guaranteed to be exclusive after a disconnect and ready for another connect. This similar fix is then applied to ip-name-lookup as well.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.mdPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested rvolosatovs for a review on PR #14266.
alexcrichton requested wasmtime-wasi-reviewers for a review on PR #14266.
alexcrichton requested pchickey for a review on PR #14266.
alexcrichton requested wasmtime-core-reviewers for a review on PR #14266.
github-actions[bot] added the label wasi on PR #14266.
:thumbs_up: rvolosatovs submitted PR review:
Looks good to me, however it looks like the
ip-name-lookupwill need asyncmodule added for p2
:speech_balloon: rvolosatovs created PR review comment:
looks like this will require adding a
syncmodule adding a non-asyncfn dropusingin_tokio, like we do for UDP already
:speech_balloon: rvolosatovs created PR review comment:
should this comment be updated?
:speech_balloon: rvolosatovs edited PR review comment.
alexcrichton updated PR #14266.
alexcrichton has enabled auto merge for PR #14266.
alexcrichton added PR #14266 Synchronize with destroying spawned tasks more in wasip2 to the merge queue.
github-merge-queue[bot] removed PR #14266 Synchronize with destroying spawned tasks more in wasip2 from the merge queue.
alexcrichton updated PR #14266.
alexcrichton has enabled auto merge for PR #14266.
alexcrichton added PR #14266 Synchronize with destroying spawned tasks more in wasip2 to the merge queue.
:check: alexcrichton merged PR #14266.
alexcrichton removed PR #14266 Synchronize with destroying spawned tasks more in wasip2 from the merge queue.
Last updated: Sep 20 2026 at 18:08 UTC