wasmerio/wasmer

Possible race condition on `virtual-fs`

Opened this issue · 1 comments

Describe the bug

Random fail linked to virtual-fs, hard to reproduce locally, it seems it's a race condition.

wasmer -vV; rustc -vV

wasmer 4.2.5 (0460050 2023-12-23)
binary: wasmer-cli
commit-hash: 04600507844bae978239531c8e6265d410aefe6d
commit-date: 2023-12-23
host: aarch64-apple-darwin
compiler: singlepass,cranelift
rustc 1.78.0-nightly (1a648b397 2024-02-11)
binary: rustc
commit-hash: 1a648b397dedc98ada3dd3360f6d661ec2436c56
commit-date: 2024-02-11
host: aarch64-apple-darwin
release: 1.78.0-nightly
LLVM version: 17.0.6

Steps to reproduce

Github repo: https://github.com/Miaxos/wasmio/
Github commit: Miaxos/wasmio@208b905
Github CI Tests that fails: https://github.com/Miaxos/wasmio/actions/runs/7902370425/job/21567897063#step:11:487

You can also run this to run the test locally, it fails at random:

RUST_BACKTRACE=full CARGO_TARGET_WASM32_WASMER_WASI_RUNNER="$(pwd)/wasmer-net" cargo wasix test -- --nocapture --

It's really hard to reproduce it in a deterministic way

Expected behavior

Should work

Actual behavior

https://github.com/Miaxos/wasmio/actions/runs/7902370425/job/21567897063#step:11:487

thread 'TokioTaskManager Thread Pool_thread_6' panicked at 'removal index (is 2) should be < len (is 2)', lib/virtual-fs/src/mem_fs/filesystem.rs:869:26
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
   2: alloc::vec::Vec<T,A>::remove::assert_failed
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/vec/mod.rs:1501:13
   3: virtual_fs::mem_fs::filesystem::FileSystemInner::remove_child_from_node
   4: <virtual_fs::mem_fs::file::FileHandle as virtual_fs::VirtualFile>::unlink::{{closure}}
   5: std::thread::local::LocalKey<T>::with
   6: futures_executor::local_pool::block_on
   7: wasmer_wasix::syscalls::wasi::path_unlink_file::path_unlink_file
   8: std::panicking::try
   9: corosensei::coroutine::on_stack::wrapper
  10: stack_call_trampoline
  11: wasmer_vm::trap::traphandlers::on_host_stack
  12: wasmer::sys::externals::function::<impl wasmer::externals::function::HostFunction<T,(A1,A2,A3),Rets,wasmer::externals::function::WithEnv> for Func>::function_callback::func_wrapper

Additional context