crossbeam-rs / crossbeam

Tools for concurrent programming in Rust
Apache License 2.0
7.27k stars 457 forks source link

crossbeam-deque work\steal panic on wasm32-wasip1-threads target #1116

Closed inklesspen1rus closed 2 months ago

inklesspen1rus commented 3 months ago

Hi! You are AWESOME :heart: ! But... Tried to run following code with wasmer and wasmtime on wasm32-wasip1-threads target and got panic

Interesting thing: release profile don't panic

Code

use crossbeam_deque::{Steal, Worker};

fn main() {
    let a = Worker::<i32>::new_fifo();
    let stealer = a.stealer();

    std::thread::spawn(move || {
        loop {
            stealer.steal().success();
        }
    });

    loop {
        if a.len() < 10240 {
            a.push(3);
        }
    }
}

Results


WASMTIME_BACKTRACE_DETAILS=1 wasmtime run -S threads=y target/wasm32-wasip1-threads/debug/test_crossbeam.wasm
thread 'main' panicked at library/core/src/panicking.rs:219:5:
unsafe precondition(s) violated: slice::from_raw_parts_mut requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
thread caused non-unwinding panic. aborting.
Error: error while executing at wasm backtrace:
    0: 0x2738a - test_crossbeam-f26e14b51eb770d4.wasm!abort
    1: 0x20e76 - std::sys::pal::wasi::helpers::abort_internal::hc892dc163f20228f
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys/pal/wasi/helpers.rs:107:14
    2: 0x2387f - std::panicking::rust_panic_with_hook::h09c989920a7c12bd
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:814:9
    3: 0x22c83 - std::panicking::begin_panic_handler::{{closure}}::h85b2a63e0cd07ae8
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:656:13
    4: 0x22bb3 - std::sys_common::backtrace::__rust_end_short_backtrace::hc0e75ce4329f8828
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys_common/backtrace.rs:171:18
    5: 0x23381 - rust_begin_unwind
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:652:5
    6: 0x2af50 - core::panicking::panic_nounwind_fmt::runtime::hdeca9fff5c5b1934
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/panicking.rs:110:18              - core::panicking::panic_nounwind_fmt::h3f477a025be41acf
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/panicking.rs:120:5
    7: 0x2afa4 - core::panicking::panic_nounwind::hdfcee379abd88bf7
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/panicking.rs:219:5
    8: 0xca95 - core::slice::raw::from_raw_parts_mut::precondition_check::h4d629f75f63f159a
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/ub_checks.rs:68:21
    9: 0xb92a - core::slice::raw::from_raw_parts_mut::hc5d48ba8d91a975e
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/ub_checks.rs:75:17
   10: 0x9c03 - crossbeam_deque::deque::Buffer<T>::dealloc::h2a8219bee2cb90cb
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-deque-0.8.5/src/deque.rs:53:28
   11: 0xa3e5 - crossbeam_deque::deque::Worker<T>::resize::{{closure}}::h9c5bd2bed7253722
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-deque-0.8.5/src/deque.rs:310:39
   12: 0x9704 - crossbeam_epoch::guard::Guard::defer_unchecked::{{closure}}::ha1b5408c5b509e27
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/guard.rs:193:52
   13: 0x6a01 - crossbeam_epoch::deferred::Deferred::new::call::hf0eaad6a1a2b8fba
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/deferred.rs:53:21
   14: 0x14c94 - crossbeam_epoch::deferred::Deferred::call::h67fadf5c4ceb717d
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/deferred.rs:86:18
   15: 0x15156 - <crossbeam_epoch::internal::Bag as core::ops::drop::Drop>::drop::he1bbf72c5ab7b787
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/internal.rs:122:13
   16: 0x19183 - core::ptr::drop_in_place<crossbeam_epoch::internal::Bag>::h94cc6a177773de43
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/ptr/mod.rs:542:1
   17: 0x18657 - core::ptr::drop_in_place<crossbeam_epoch::internal::SealedBag>::hbacd13dc427ab97b
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/ptr/mod.rs:542:1
   18: 0x18627 - core::mem::drop::hcad8aacc00fe2fad
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/mem/mod.rs:938:24
   19: 0x15ddd - crossbeam_epoch::internal::Global::collect::h8d6c218a8fe3c576
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/internal.rs:214:37
   20: 0x6ca8 - crossbeam_epoch::internal::Local::pin::h8c1dbc9032910b5b
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/internal.rs:435:17
   21: 0xb605 - crossbeam_epoch::collector::LocalHandle::pin::h296e34125c298c2a
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/collector.rs:81:18
   22: 0xdb84 - crossbeam_epoch::default::pin::{{closure}}::h2623f29f6a9e5c71
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/default.rs:40:26
   23: 0xdc96 - crossbeam_epoch::default::with_handle::{{closure}}::hb3944eadc938e536
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/default.rs:60:23
   24: 0xc56c - std::thread::local::LocalKey<T>::try_with::h3e57ba7464f4ef4a
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/thread/local.rs:286:12
   25: 0xd9e9 - crossbeam_epoch::default::with_handle::h2e80bd097a1a3bba
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/default.rs:59:5
   26: 0x65c6 - crossbeam_epoch::default::pin::hccf9a1e84958a464
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/default.rs:40:5
   27: 0xa7d2 - crossbeam_deque::deque::Stealer<T>::steal::h3a3a63fa27f7cc4f
                    at /home/inklesspen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-deque-0.8.5/src/deque.rs:645:22
   28: 0x66f3 - test_crossbeam::main::{{closure}}::hbd36ed0ffd8f8780
                    at /home/inklesspen/Documents/tests/rust/wasm/test_crossbeam/src/main.rs:9:13
   29: 0x441c - std::sys_common::backtrace::__rust_begin_short_backtrace::h9eb2f5de2b4450c3
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys_common/backtrace.rs:155:18
   30: 0x2037 - std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}::hb91de4c7778fa635
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/thread/mod.rs:542:17
   31: 0xb893 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h8b5c50d0e788d37f
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/panic/unwind_safe.rs:272:9
   32: 0xcc04 - std::panicking::try::do_call::h634078a36f4fa557
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:559:40
   33: 0xcb08 - std::panicking::try::h663da41667773a0e
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panicking.rs:523:19
   34: 0x1b8e - std::panic::catch_unwind::h5dacb3751d0fddc7
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/panic.rs:149:14              - std::thread::Builder::spawn_unchecked_::{{closure}}::h200d8678b6f6c061
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/thread/mod.rs:541:30
   35: 0x6e97 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h55eec34984f90e1e
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/core/src/ops/function.rs:250:5
   36: 0x23ea0 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf1e30f8eeac8305a
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/alloc/src/boxed.rs:2063:9              - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2b23e9b19411e72c
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/alloc/src/boxed.rs:2063:9              - std::sys::pal::wasi::thread::Thread::new::thread_start::h2bbb5da560b50d7c
                    at /rustc/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd/library/std/src/sys/pal/wasi/thread.rs:116:25
   37: 0x28208 - test_crossbeam-f26e14b51eb770d4.wasm!__wasi_thread_start_C
   38: 0x28d82 - test_crossbeam-f26e14b51eb770d4.wasm!wasi_thread_start

Caused by:
    wasm trap: wasm `unreachable` instruction executed
$ wasmer run -- target/wasm32-wasip1-threads/debug/test_crossbeam.wasm
thread 'main' panicked at library/core/src/panicking.rs:219:5:
unsafe precondition(s) violated: slice::from_raw_parts_mut requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
thread caused non-unwinding panic. aborting.

Environment

wasmer 4.3.1 wasmtime-cli 21.0.1 (cedf9aa0f 2024-05-22) inxi -vvva: CPU: 6-core AMD Ryzen 5 5625U with Radeon Graphics (-MT MCP-) speed/min/max: 2039/400/4388 MHz Kernel: 6.9.0-1-MANJARO x86_64 Up: 3d 2h 23m Mem: 9.93/15.01 GiB (66.2%) Storage: 476.94 GiB (24.8% used) Procs: 650 Shell: Zsh 5.9 inxi: 3.3.34

inklesspen1rus commented 3 months ago

I'm testing on nightly version of rust

rustup 1.27.1 (54dd3d00f 2024-04-24) info: This is the version for the rustup toolchain manager, not the rustc compiler. info: The currently active rustc version is rustc 1.80.0-nightly (ada5e2c7b 2024-05-31)

Also, stable version works fine o_0

rustup 1.27.1 (54dd3d00f 2024-04-24) info: This is the version for the rustup toolchain manager, not the rustc compiler. info: The currently active rustc version is rustc 1.78.0 (9b00956e5 2024-04-29)

taiki-e commented 3 months ago

Hmm. It seems that Inner::buffer has become null for some reason. But I cannot find any code that seems to make it null. And I cannot reproduce this on other 32-bit targets so I feel it may be a platform issue.

bbb651 commented 3 months ago

I'm getting a different issue also in crossbeam-deque targeting wasm32-wasip1-threads, I'm not if the problem is even in crossbeam because I'm always getting memory allocation of 133120 bytes failed before the actual panic, but it's reproducible on wasmer, wastime and iwasm. It's trigger by creating a nucleo Nucleo instance:

use nucleo::{Config, Nucleo};

fn main() {
        let mut nucleo: Nucleo<String> = Nucleo::new(Config::DEFAULT, Arc::new(|| {}), Some(1), 1);
}
cargo b --target=wasm32-wasip1-threads

(printing is a bit racey and changes a bit each time, memory allocation of 133120 bytes failed prints as thread \` panicked...` is printing)

❯ wasmer run ./target/wasm32-wasip1-threads/debug/f.wasm
memory allocation of 133120thread ' bytes failed
<unnamed>' panicked at /home/bbb651/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-deque-0.8.5/src/deque.rs:64:33error: RuntimeError: unreachable
    at abort (f-6c7c88893f5c911f.wasm[1887]:0x6d277)
    at std::sys::pal::wasi::helpers::abort_internal::hd621692127b9daa9 (f-6c7c88893f5c911f.wasm[1782]:0x66057)
    at std::process::abort::hd54ee46f43c5cd26 (f-6c7c88893f5c911f.wasm[1816]:0x68067)
    at std::alloc::rust_oom::hd4bcd7215041ce28 (f-6c7c88893f5c911f.wasm[1855]:0x69c61)
    at __rg_oom (f-6c7c88893f5c911f.wasm[1856]:0x69c6f)
    at __rust_alloc_error_handler (f-6c7c88893f5c911f.wasm[265]:0xea62)
    at alloc::alloc::handle_alloc_error::haced9e87ced732f5 (f-6c7c88893f5c911f.wasm[1939]:0x6eea5)
    at nucleo_matcher::matrix::MatrixSlab::new::h615350e8830d8a59 (f-6c7c88893f5c911f.wasm[307]:0x115eb)
    at nucleo_matcher::Matcher::new::he6b151bfd4749d34 (f-6c7c88893f5c911f.wasm[309]:0x11668)
    at nucleo::worker::Worker<T>::new::{{closure}}::h715eac0a4a8550cf (f-6c7c88893f5c911f.wasm[54]:0x5280)
    at core::iter::adapters::map::map_fold::{{closure}}::h4af07fdd8bd953d5 (f-6c7c88893f5c911f.wasm[197]:0xb193)
    at core::iter::traits::iterator::Iterator::fold::he753264b94b8d07b (f-6c7c88893f5c911f.wasm[79]:0x6844)
    at <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::he8d93fa8241deb72 (f-6c7c88893f5c911f.wasm[190]:0xaf0b)
    at core::iter::traits::iterator::Iterator::for_each::h924e7efb51717c5f (f-6c7c88893f5c911f.wasm[196]:0xb117)
    at alloc::vec::Vec<T,A>::extend_trusted::hea060507b3d2e463 (f-6c7c88893f5c911f.wasm[255]:0xe5e4)
    at <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend::h3d99dbe441301a5f (f-6c7c88893f5c911f.wasm[250]:0xe221)
    at <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter::h4db9eb1b740aa1fe (f-6c7c88893f5c911f.wasm[249]:0xe105)
    at <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::ha93efd3577cb99b8 (f-6c7c88893f5c911f.wasm[260]:0xea04)
    at <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter::hd8b254c338f6c905 (f-6c7c88893f5c911f.wasm[259]:0xe9e3)
    at core::iter::traits::iterator::Iterator::collect::hd58476b4627c65f0 (f-6c7c88893f5c911f.wasm[195]:0xb0b6)
    at <alloc::boxed::Box<[I]> as core::iter::traits::collect::FromIterator<I>>::from_iter::hd60a35feaf71d91b (f-6c7c88893f5c911f.wasm[92]:0x6fbd)
    at core::iter::traits::iterator::Iterator::collect::h9e8c5bb987f62e14 (f-6c7c88893f5c911f.wasm[194]:0xb079)
    at nucleo::worker::Worker<T>::new::h5efa456836f88faa (f-6c7c88893f5c911f.wasm[51]:0x4d7e)
    at nucleo::Nucleo<T>::new::h63144caa3f818fc9 (f-6c7c88893f5c911f.wasm[217]:0xbf5e)
    at f::main::h3a1622b536ea17d9 (f-6c7c88893f5c911f.wasm[95]:0x72a4)
    at core::ops::function::FnOnce::call_once::hdd5b7db5cebb71b8 (f-6c7c88893f5c911f.wasm[106]:0x7634)
    at std::sys_common::backtrace::__rust_begin_short_backtrace::hcaa5b5e9f10c5d27 (f-6c7c88893f5c911f.wasm[218]:0xc361)
    at std::rt::lang_start::{{closure}}::h93b5b4222cdcb8ee (f-6c7c88893f5c911f.wasm[221]:0xc526)
    at std::rt::lang_start_internal::h90b030aff06a1679 (f-6c7c88893f5c911f.wasm[1780]:0x65f1d)
    at std::rt::lang_start::haf5e3f2b9cb52289 (f-6c7c88893f5c911f.wasm[220]:0xc4c2)
    at __main_void (f-6c7c88893f5c911f.wasm[96]:0x72f3)
    at _start (f-6c7c88893f5c911f.wasm[10]:0xc60)
╰─▶ 1: RuntimeError: unreachable
           at abort (f-6c7c88893f5c911f.wasm[1887]:0x6d277)
           at std::sys::pal::wasi::helpers::abort_internal::hd621692127b9daa9 (f-6c7c88893f5c911f.wasm[1782]:0x66057)
           at std::process::abort::hd54ee46f43c5cd26 (f-6c7c88893f5c911f.wasm[1816]:0x68067)
           at std::alloc::rust_oom::hd4bcd7215041ce28 (f-6c7c88893f5c911f.wasm[1855]:0x69c61)
           at __rg_oom (f-6c7c88893f5c911f.wasm[1856]:0x69c6f)
           at __rust_alloc_error_handler (f-6c7c88893f5c911f.wasm[265]:0xea62)
           at alloc::alloc::handle_alloc_error::haced9e87ced732f5 (f-6c7c88893f5c911f.wasm[1939]:0x6eea5)
           at nucleo_matcher::matrix::MatrixSlab::new::h615350e8830d8a59 (f-6c7c88893f5c911f.wasm[307]:0x115eb)
           at nucleo_matcher::Matcher::new::he6b151bfd4749d34 (f-6c7c88893f5c911f.wasm[309]:0x11668)
           at nucleo::worker::Worker<T>::new::{{closure}}::h715eac0a4a8550cf (f-6c7c88893f5c911f.wasm[54]:0x5280)
           at core::iter::adapters::map::map_fold::{{closure}}::h4af07fdd8bd953d5 (f-6c7c88893f5c911f.wasm[197]:0xb193)
           at core::iter::traits::iterator::Iterator::fold::he753264b94b8d07b (f-6c7c88893f5c911f.wasm[79]:0x6844)
           at <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::he8d93fa8241deb72 (f-6c7c88893f5c911f.wasm[190]:0xaf0b)
           at core::iter::traits::iterator::Iterator::for_each::h924e7efb51717c5f (f-6c7c88893f5c911f.wasm[196]:0xb117)
           at alloc::vec::Vec<T,A>::extend_trusted::hea060507b3d2e463 (f-6c7c88893f5c911f.wasm[255]:0xe5e4)
           at <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend::h3d99dbe441301a5f (f-6c7c88893f5c911f.wasm[250]:0xe221)
           at <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter::h4db9eb1b740aa1fe (f-6c7c88893f5c911f.wasm[249]:0xe105)
           at <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::ha93efd3577cb99b8 (f-6c7c88893f5c911f.wasm[260]:0xea04)
           at <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter::hd8b254c338f6c905 (f-6c7c88893f5c911f.wasm[259]:0xe9e3)
           at core::iter::traits::iterator::Iterator::collect::hd58476b4627c65f0 (f-6c7c88893f5c911f.wasm[195]:0xb0b6)
           at <alloc::boxed::Box<[I]> as core::iter::traits::collect::FromIterator<I>>::from_iter::hd60a35feaf71d91b (f-6c7c88893f5c911f.wasm[92]:0x6fbd)
           at core::iter::traits::iterator::Iterator::collect::h9e8c5bb987f62e14 (f-6c7c88893f5c911f.wasm[194]:0xb079)
           at nucleo::worker::Worker<T>::new::h5efa456836f88faa (f-6c7c88893f5c911f.wasm[51]:0x4d7e)
           at nucleo::Nucleo<T>::new::h63144caa3f818fc9 (f-6c7c88893f5c911f.wasm[217]:0xbf5e)
           at f::main::h3a1622b536ea17d9 (f-6c7c88893f5c911f.wasm[95]:0x72a4)
           at core::ops::function::FnOnce::call_once::hdd5b7db5cebb71b8 (f-6c7c88893f5c911f.wasm[106]:0x7634)
           at std::sys_common::backtrace::__rust_begin_short_backtrace::hcaa5b5e9f10c5d27 (f-6c7c88893f5c911f.wasm[218]:0xc361)
           at std::rt::lang_start::{{closure}}::h93b5b4222cdcb8ee (f-6c7c88893f5c911f.wasm[221]:0xc526)
           at std::rt::lang_start_internal::h90b030aff06a1679 (f-6c7c88893f5c911f.wasm[1780]:0x65f1d)
           at std::rt::lang_start::haf5e3f2b9cb52289 (f-6c7c88893f5c911f.wasm[220]:0xc4c2)
           at __main_void (f-6c7c88893f5c911f.wasm[96]:0x72f3)
           at _start (f-6c7c88893f5c911f.wasm[10]:0xc60)

As I'm writing this, I tired to simplify the example and slightly changed the code from Some(1) to None, causing nucleo to change the number of thread in the threadpool:

// ...
let worker_threads = worker_threads
    .unwrap_or_else(|| std::thread::available_parallelism().map_or(4, |it| it.get()));
let pool = rayon::ThreadPoolBuilder::new()
    .thread_name(|i| format!("nucleo worker {i}"))
    .num_threads(worker_threads)
    .build()
    .expect("creating threadpool failed");
// ...

and managed to reproduce this exact panic:

❯ wasmer run ./target/wasm32-wasip1-threads/debug/f.wasm
thread '<unnamed>' panicked at library/core/src/panicking.rs:156:5:
unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
error: RuntimeError: out of bounds memory access
    at dlmalloc (f-6c7c88893f5c911f.wasm[1869]:0x6a2f7)
    at realloc (f-6c7c88893f5c911f.wasm[1873]:0x6c812)
    at __rdl_realloc (f-6c7c88893f5c911f.wasm[1833]:0x68bdd)
    at __rust_realloc (f-6c7c88893f5c911f.wasm[263]:0xea31)
    at alloc::raw_vec::finish_grow::h5db88e7aa4d3da4d (f-6c7c88893f5c911f.wasm[1938]:0x6ee2a)
    at alloc::ffi::c_str::CString::_from_vec_unchecked::h7c2114d19a138e92 (f-6c7c88893f5c911f.wasm[1943]:0x6f232)
    at <T as alloc::ffi::c_str::CString::new::SpecNewImpl>::spec_new_impl::h8d6cd8bb46dd2544 (f-6c7c88893f5c911f.wasm[641]:0x2abf3)
    at std::thread::Builder::spawn_unchecked_::hbd37aeff6ecfafeb (f-6c7c88893f5c911f.wasm[805]:0x32227)
    at std::thread::Builder::spawn_unchecked::hed05dc885d9588c1 (f-6c7c88893f5c911f.wasm[804]:0x31d4b)
    at std::thread::Builder::spawn::hd1fdc04ae3b662f0 (f-6c7c88893f5c911f.wasm[814]:0x342fc)
    at <rayon_core::registry::DefaultSpawn as rayon_core::registry::ThreadSpawn>::spawn::ha25b26c66933259e (f-6c7c88893f5c911f.wasm[573]:0x259c7)
    at rayon_core::registry::Registry::new::h36b778a7deba5b0c (f-6c7c88893f5c911f.wasm[575]:0x26b7f)
    at rayon_core::thread_pool::ThreadPool::build::h4c26f42651824f8c (f-6c7c88893f5c911f.wasm[491]:0x1c5ad)
    at rayon_core::ThreadPoolBuilder<S>::build::h748d8853ee8513f4 (f-6c7c88893f5c911f.wasm[754]:0x2fc72)
    at nucleo::worker::Worker<T>::new::h5efa456836f88faa (f-6c7c88893f5c911f.wasm[51]:0x4cd0)
    at nucleo::Nucleo<T>::new::h63144caa3f818fc9 (f-6c7c88893f5c911f.wasm[217]:0xbf53)
    at f::main::h3a1622b536ea17d9 (f-6c7c88893f5c911f.wasm[95]:0x7299)
    at core::ops::function::FnOnce::call_once::hdd5b7db5cebb71b8 (f-6c7c88893f5c911f.wasm[106]:0x7629)
    at std::sys_common::backtrace::__rust_begin_short_backtrace::hcaa5b5e9f10c5d27 (f-6c7c88893f5c911f.wasm[218]:0xc356)
    at std::rt::lang_start::{{closure}}::h93b5b4222cdcb8ee (f-6c7c88893f5c911f.wasm[221]:0xc51b)
    at std::rt::lang_start_internal::h90b030aff06a1679 (f-6c7c88893f5c911f.wasm[1780]:0x65f12)
    at std::rt::lang_start::haf5e3f2b9cb52289 (f-6c7c88893f5c911f.wasm[220]:0xc4b7)
    at __main_void (f-6c7c88893f5c911f.wasm[96]:0x72e8)
    at _start (f-6c7c88893f5c911f.wasm[10]:0xc60)
╰─▶ 1: RuntimeError: out of bounds memory access
           at dlmalloc (f-6c7c88893f5c911f.wasm[1869]:0x6a2f7)
           at realloc (f-6c7c88893f5c911f.wasm[1873]:0x6c812)
           at __rdl_realloc (f-6c7c88893f5c911f.wasm[1833]:0x68bdd)
           at __rust_realloc (f-6c7c88893f5c911f.wasm[263]:0xea31)
           at alloc::raw_vec::finish_grow::h5db88e7aa4d3da4d (f-6c7c88893f5c911f.wasm[1938]:0x6ee2a)
           at alloc::ffi::c_str::CString::_from_vec_unchecked::h7c2114d19a138e92 (f-6c7c88893f5c911f.wasm[1943]:0x6f232)
           at <T as alloc::ffi::c_str::CString::new::SpecNewImpl>::spec_new_impl::h8d6cd8bb46dd2544 (f-6c7c88893f5c911f.wasm[641]:0x2abf3)
           at std::thread::Builder::spawn_unchecked_::hbd37aeff6ecfafeb (f-6c7c88893f5c911f.wasm[805]:0x32227)
           at std::thread::Builder::spawn_unchecked::hed05dc885d9588c1 (f-6c7c88893f5c911f.wasm[804]:0x31d4b)
           at std::thread::Builder::spawn::hd1fdc04ae3b662f0 (f-6c7c88893f5c911f.wasm[814]:0x342fc)
           at <rayon_core::registry::DefaultSpawn as rayon_core::registry::ThreadSpawn>::spawn::ha25b26c66933259e (f-6c7c88893f5c911f.wasm[573]:0x259c7)
           at rayon_core::registry::Registry::new::h36b778a7deba5b0c (f-6c7c88893f5c911f.wasm[575]:0x26b7f)
           at rayon_core::thread_pool::ThreadPool::build::h4c26f42651824f8c (f-6c7c88893f5c911f.wasm[491]:0x1c5ad)
           at rayon_core::ThreadPoolBuilder<S>::build::h748d8853ee8513f4 (f-6c7c88893f5c911f.wasm[754]:0x2fc72)
           at nucleo::worker::Worker<T>::new::h5efa456836f88faa (f-6c7c88893f5c911f.wasm[51]:0x4cd0)
           at nucleo::Nucleo<T>::new::h63144caa3f818fc9 (f-6c7c88893f5c911f.wasm[217]:0xbf53)
           at f::main::h3a1622b536ea17d9 (f-6c7c88893f5c911f.wasm[95]:0x7299)
           at core::ops::function::FnOnce::call_once::hdd5b7db5cebb71b8 (f-6c7c88893f5c911f.wasm[106]:0x7629)
           at std::sys_common::backtrace::__rust_begin_short_backtrace::hcaa5b5e9f10c5d27 (f-6c7c88893f5c911f.wasm[218]:0xc356)
           at std::rt::lang_start::{{closure}}::h93b5b4222cdcb8ee (f-6c7c88893f5c911f.wasm[221]:0xc51b)
           at std::rt::lang_start_internal::h90b030aff06a1679 (f-6c7c88893f5c911f.wasm[1780]:0x65f12)
           at std::rt::lang_start::haf5e3f2b9cb52289 (f-6c7c88893f5c911f.wasm[220]:0xc4b7)
           at __main_void (f-6c7c88893f5c911f.wasm[96]:0x72e8)
           at _start (f-6c7c88893f5c911f.wasm[10]:0xc60)
taiki-e commented 2 months ago

Closing in favor of upstream bug report: https://github.com/rust-lang/rust/issues/126747