wasmerio/wasmer

Wasix: Panic on thread::sleep() from doc example

alexeiaguiar opened this issue · 3 comments

Describe the bug

wasmer -vV; rustc -vV

wasmer 4.0.0 (77898a7 2023-06-22)
binary: wasmer-cli
commit-hash: 77898a7767eb7057834fdc1a80b239e6b68cf44e
commit-date: 2023-06-22
host: x86_64-unknown-linux-gnu
compiler: singlepass,cranelift,llvm
rustc 1.71.0 (8ede3aae2 2023-07-12)
binary: rustc
commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225
commit-date: 2023-07-12
host: x86_64-unknown-linux-gnu
release: 1.71.0
LLVM version: 16.0.5

cargo wasix --version
cargo-wasix 0.1.20

Same also happens on my Mac M1:

wasmer -vV; rustc -vV
wasmer 4.0.0 (77898a7 2023-06-22)
binary: wasmer-cli
commit-hash: 77898a7767eb7057834fdc1a80b239e6b68cf44e
commit-date: 2023-06-22
host: aarch64-apple-darwin
compiler: singlepass,cranelift
rustc 1.71.0 (8ede3aae2 2023-07-12)
binary: rustc
commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225
commit-date: 2023-07-12
host: aarch64-apple-darwin
release: 1.71.0
LLVM version: 16.0.5

cargo wasix --version
cargo-wasix 0.1.20

Steps to reproduce

Follow the instructions of the Rust thread example:
https://wasix.org/docs/language-guide/rust/tutorials/threading

Expected behavior

$ cargo wasix run
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
     Running `cargo-wasix target/wasm32-wasmer-wasi/debug/wasix-threading.wasm`
info: Post-processing WebAssembly files
     Running `target/wasm32-wasmer-wasi/debug/wasix-threading.wasm`
hi number 1 from the main thread!
hi number 1 from the spawned thread!
hi number 2 from the main thread!
hi number 2 from the spawned thread!
hi number 3 from the main thread!
hi number 3 from the spawned thread!
hi number 4 from the main thread!
hi number 4 from the spawned thread!
hi number 5 from the spawned thread!
hi number 6 from the spawned thread!
hi number 7 from the spawned thread!
hi number 8 from the spawned thread!
hi number 9 from the spawned thread!

Actual behavior

$ cargo wasix run
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `/home/aaguiar/.cargo/bin/cargo-wasix target/wasm32-wasmer-wasi/debug/wasix-threading.wasm`
info: Post-processing WebAssembly files
     Running `target/wasm32-wasmer-wasi/debug/wasix-threading.wasm`
hi number 1 from the main thread!
thread 'hi number 1 from the spawned thread!
main' panicked at 'assertion failed: `(left == right)`
  left: `58`,
 right: `27`', thread 'library/std/src/sys/wasix/../unix/thread.rs:<unnamed>278:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
' panicked at 'assertion failed: `(left == right)`
  left: `58`,
 right: `27`', library/std/src/sys/wasix/../unix/thread.rs:278:21
error: RuntimeError: unreachable
    at __rust_start_panic (<module>[544]:0x1a95b)
    at rust_panic (<module>[88]:0xe343)
    at std::panicking::rust_panic_with_hook::h9263954d568f9a22 (<module>[22]:0x4385)
    at std::panicking::begin_panic_handler::{{closure}}::he2a885ef2c7daf67 (<module>[204]:0x15bdb)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h0990da56f6cdfd88 (<module>[506]:0x1a801)
    at rust_begin_unwind (<module>[290]:0x182e9)
    at core::panicking::panic_fmt::he2d14375ce2ede15 (<module>[358]:0x19674)
    at core::panicking::assert_failed_inner::hd62ba34eed461b63 (<module>[63]:0xbab9)
    at core::panicking::assert_failed::h4d3a5e37d36d0460 (<module>[251]:0x17464)
    at std::thread::sleep::hd4c734742470805b (<module>[178]:0x148b6)
    at wasix_threading::main::h688b4fb6d0a671a4 (<module>[54]:0xa99b)
    at core::ops::function::FnOnce::call_once::hb0866bb48b34a83f (<module>[362]:0x19734)
    at std::sys_common::backtrace::__rust_begin_short_backtrace::h154e7fc9c184acc8 (<module>[382]:0x19b40)
    at std::rt::lang_start::{{closure}}::hb7f87a14d467d4a5 (<module>[247]:0x17280)
    at std::rt::lang_start_internal::h08e775817fb89cc1 (<module>[286]:0x18168)
    at std::rt::lang_start::hbe8f4d0efc65a3ed (<module>[225]:0x1682a)
    at __main_void (<module>[418]:0x1a1ae)
    at _start (<module>[397]:0x19e24)
╰─▶ 1: RuntimeError: unreachable
           at __rust_start_panic (<module>[544]:0x1a95b)
           at rust_panic (<module>[88]:0xe343)
           at std::panicking::rust_panic_with_hook::h9263954d568f9a22 (<module>[22]:0x4385)
           at std::panicking::begin_panic_handler::{{closure}}::he2a885ef2c7daf67 (<module>[204]:0x15bdb)
           at std::sys_common::backtrace::__rust_end_short_backtrace::h0990da56f6cdfd88 (<module>[506]:0x1a801)
           at rust_begin_unwind (<module>[290]:0x182e9)
           at core::panicking::panic_fmt::he2d14375ce2ede15 (<module>[358]:0x19674)
           at core::panicking::assert_failed_inner::hd62ba34eed461b63 (<module>[63]:0xbab9)
           at core::panicking::assert_failed::h4d3a5e37d36d0460 (<module>[251]:0x17464)
           at std::thread::sleep::hd4c734742470805b (<module>[178]:0x148b6)
           at wasix_threading::main::h688b4fb6d0a671a4 (<module>[54]:0xa99b)
           at core::ops::function::FnOnce::call_once::hb0866bb48b34a83f (<module>[362]:0x19734)
           at std::sys_common::backtrace::__rust_begin_short_backtrace::h154e7fc9c184acc8 (<module>[382]:0x19b40)
           at std::rt::lang_start::{{closure}}::hb7f87a14d467d4a5 (<module>[247]:0x17280)
           at std::rt::lang_start_internal::h08e775817fb89cc1 (<module>[286]:0x18168)
           at std::rt::lang_start::hbe8f4d0efc65a3ed (<module>[225]:0x1682a)
           at __main_void (<module>[418]:0x1a1ae)
           at _start (<module>[397]:0x19e24)

Additional context

Thanks for the ping, we'll investigate the issue shortly

@alexeiaguiar can you update wasmer to the 4.1.0 and try again? It should be fixed there.

It indeed fixed the problem in both Linux and MacOS. Thanks!