Repository navigation
release borrows before task.return - #256
Merged
dicej merged 2 commits intoOct 30, 2026
Merged
Conversation
added 2 commits
October 29, 2026 23:16
Add an async world export that takes a `borrow` of an imported resource, and a host test that calls it. The Canonical ABI requires every borrow lent to a task to be released before `task.return`, so this currently traps with "borrow handles still remain at the end of the call".
The Canonical ABI traps if a task returns while any borrow lent to it is still outstanding. `call_task_return` called `task.return` first and released the borrows afterwards, so every async-lifted export that took a `borrow` trapped with "borrow handles still remain at the end of the call" on Wasmtime 43 and later. Release the borrows first. Results can't hold borrows, so lowering them afterwards is unaffected. Fixes bytecodealliance#255
dicej
approved these changes
Oct 30, 2026
dicej
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, @FrancoisLDaigneault!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Async-lifted exports that receive a
borrow<T>trap when the Python coroutine returns:async_::call_task_returncallstask.returnfirst and releases the borrows afterwards. The Canonical ABI requires the opposite order:Task.return_indesign/mvp/canonical-abi/definitions.pyrunstrap_if(self.num_borrows > 0)before it resolves the task, andConcurrency.md("Borrows") says that a callee which returns whilenum_borrowsis greater than zero traps. Wasmtime 43 and later enforce this, andmainbuilds against Wasmtime 48. The synchronous path already releases borrows before returning.This change releases the borrows first, then calls
task.return. A result type can't hold aborrow<T>, so lowering the results afterwards is unaffected.The first commit adds the regression test: an async world export that takes a
borrowof an imported resource, with its guest method and a host test. The second commit is the fix.Fork runs of the
Testworkflow:resource_borrow_import_async_exportfails with the trap above (126 passed, 1 failed).Fixes #255