Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/wasix/src/syscalls/wasix/thread_spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ fn call_module_internal<M: MemorySize>(

let exit_code = handle_thread_result(env, store, thread_result)?;

// Fix for issue #5501: When a thread exits with a non-zero exit code (e.g., from abort()),
// we must set the thread's status BEFORE calling on_exit(). This is because on_exit()
// eventually calls process.terminate() which propagates the exit code to all threads.
// Without setting the status first, there's a race where the thread handle cleanup
// (WasiThreadHandleProtected::drop) could set the status to Success(0) before the
// correct exit code is recorded. The existing test `test_snapshot_worker_panicking`
// validates this behavior by ensuring a trap in a worker thread results in exit code 173.
if let Some(code) = exit_code {
env.data(store).thread.set_status_finished(Ok(code));
}

// Clean up the environment on exit
env.on_exit(store, exit_code);
Ok(())
Expand Down