Skip to content

dd and sort -m trap under WASI because they spawn real OS threads #16599

Open

Description

@eduardomourar

Description

WASI has no real threads; std::thread::spawn always fails. Two spots spawn one unconditionally, with no fallback, and both panic into a wasm unreachable trap instead of returning an error:

  • dd_copy (src/uu/dd/src/dd.rs): always spawns a progress-reporting thread and a periodic-alarm thread, even without status=progress.
  • uu_sort's external merge path (src/uu/sort/src/merge.rs): spawns a thread per merge batch.
thread 'main' panicked at .../thread/functions.rs:...:
failed to spawn thread: Os { code: 58, kind: Unsupported, message: "Not supported" }
...
2: wasm trap: wasm `unreachable` instruction executed

Impact

  • Almost every real dd invocation under WASI hits the thread spawn.
  • Many sort tests carry #[uutests::wasi_ignore(NoThreadSpawning)] for the same reason, on the merge path.
  • Unlike subprocess spawning, this has a real local fix available now: a non-threaded code path for target_os = "wasi" (report progress inline, merge batches sequentially).

Is there a way around this, upstream?

Two generations:

  • wasi-threads: shipped wasi_thread_spawn() for preview1, once supported by Wasmtime/WAMR/Wasmer/toywasm plus wasi-libc pthreads on wasm32-wasip1-threads. Its own README calls it legacy. Confirmed dead with current tooling: building the same std::thread::spawn program for wasm32-wasip1-threads and running wasmtime run -S threads=y ... (wasmtime 50.x, what this repo's CI installs) fails with the -Sthreads flag is no longer supported, despite --help still listing it.
  • shared-everything-threads: the actual successor, for WASI v0.2+/component model. Draft, no phase, not implemented in wasmtime. This is the one to track.

Either would add real thread spawning within a single module instance — exactly what std::thread::spawn needs, so dd/sort would work unmodified. Different from wasi:exec (a separate process/component, not a thread) — that one is only a partial fix for the subprocess-spawning issue; this proposal is a complete fix for dd/sort.

Ask

  • Track shared-everything-threads upstream; nothing to build against today. Don't pursue wasm32-wasip1-threads/wasi-threads — confirmed dead on current wasmtime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions