Fix: Abort in WASIX thread now returns non-zero exit code #5905
+11
−0
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.
Description
Fixes #5501 - Calling
abort()from a WASIX worker thread was causing wasmer to exit with code 0 instead of a non-zero exit code.Root cause: Race condition in thread cleanup sequence. When a worker thread encounters a runtime error (e.g., WASM trap from
abort()),handle_thread_result()correctly returns the exit code (129), buton_exit()runs asynchronously. The thread handle cleanup (WasiThreadHandleProtected::drop) could execute before the exit code was recorded, and its attempt to set status toSuccesswould win the race.Fix: Explicitly set the thread's status with
set_status_finished()before callingon_exit()when exiting with a non-zero code. This ensures the exit code is captured before any cleanup runs.Test coverage: The existing
test_snapshot_worker_panickingtest intests/integration/cli/tests/snapshot.rsvalidates this fix. It tests a panic in a worker thread (which causes a WASM trap similar toabort()) and asserts the exit code is 173 (non-zero, not 0).Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.