This repository was archived by the owner on Sep 8, 2025. It is now read-only.
change the error returned by Instance::run etc. on deadlock#155
Merged
Conversation
Previously, we returned an "async-lifted export failed to return a result" which was not always accurate and usually misleading. This also adds documentation to `Instance::run` explaining when and why a "deadlock" error will be returned. Note that the new `backpressure-deadlock.wast` test was copied from Alex Crichton's issue description. Fixes #152 Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Contributor
|
Hah, I just ran into the same thing. If you'd like a second test case for the same error condition but exercised differently: (component
(component $C
(core module $Memory (memory (export "mem") 1))
(core instance $memory (instantiate $Memory))
(core module $CM
(import "" "mem" (memory 1))
(import "" "waitable-set.new" (func $waitable-set.new (result i32)))
(func (export "f") (result i32)
(local $ws i32)
;; return WAIT on an empty waitable set
(local.set $ws (call $waitable-set.new))
(i32.or (i32.const 2 (; WAIT ;)) (i32.shl (local.get $ws) (i32.const 4)))
)
(func (export "cb") (param $event_code i32) (param $index i32) (param $payload i32) (result i32)
unreachable
)
)
(canon waitable-set.new (core func $waitable-set.new))
(core instance $cm (instantiate $CM (with "" (instance
(export "mem" (memory $memory "mem"))
(export "waitable-set.new" (func $waitable-set.new))
))))
(func (export "f") (result u32) (canon lift
(core func $cm "f")
async (memory $memory "mem") (callback (func $cm "cb"))
))
)
(component $D
(import "f" (func $f (result u32)))
(core module $Memory (memory (export "mem") 1))
(core instance $memory (instantiate $Memory))
(core module $DM
(import "" "mem" (memory 1))
(import "" "waitable.join" (func $waitable.join (param i32 i32)))
(import "" "waitable-set.new" (func $waitable-set.new (result i32)))
(import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))
(import "" "f" (func $f (param i32 i32) (result i32)))
(func (export "g") (result i32)
(local $ws i32) (local $ret i32) (local $subtaski i32)
(local.set $ws (call $waitable-set.new))
(local.set $ret (call $f (i32.const 0) (i32.const 0)))
(local.set $subtaski (i32.shr_u (local.get $ret) (i32.const 4)))
(call $waitable.join (local.get $subtaski) (local.get $ws))
(call $waitable-set.wait (local.get $ws) (i32.const 0))
unreachable
)
)
(canon waitable.join (core func $waitable.join))
(canon waitable-set.new (core func $waitable-set.new))
(canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))
(canon lower (func $f) async (memory $memory "mem") (core func $f'))
(core instance $dm (instantiate $DM (with "" (instance
(export "mem" (memory $memory "mem"))
(export "waitable.join" (func $waitable.join))
(export "waitable-set.new" (func $waitable-set.new))
(export "waitable-set.wait" (func $waitable-set.wait))
(export "f" (func $f'))
))))
(func (export "f") (result u32) (canon lift (core func $dm "g")))
)
(instance $c (instantiate $C))
(instance $d (instantiate $D (with "f" (func $c "f"))))
(func (export "f") (alias export $d "f"))
)
(assert_trap (invoke "f") "deadlock detected") |
Collaborator
Author
|
@lukewagner thanks for the extra test; I'll add it. As I added Alex's test, I noticed we already had another one that triggered this error, so now we have three total. |
This creates a new `AsyncDeadlock` variant to the `Trap` enum, allowing application code to downcast to `Trap` rather than do a string match to handle the error programmatically. Thanks to Luke Wagner for the additional test case. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Previously, we returned an "async-lifted export failed to return a result" which was not always accurate and usually misleading.
This also adds documentation to
Instance::runexplaining when and why a "deadlock" error will be returned.Note that the new
backpressure-deadlock.wasttest was copied from Alex Crichton's issue description.Fixes #152