Skip to content

Exit codes >= 126 crash the WASI build instead of exiting cleanly #16594

Open

Description

@eduardomourar

Description

wasi_snapshot_preview1::proc_exit only accepts exit statuses in [0, 126). A status at or above that range makes wasmtime trap the whole module, instead of exiting with that status.

Several utilities use exit codes in that reserved range on purpose, following shell convention:

  • 126: command found but not executable (nice, env, nohup, timeout)
  • 127: command not found (nice, env, nohup, timeout)
  • 128 + signal: process killed by a signal (timeout, stdbuf)

Under the feat_wasm build, these codes are reachable even though the underlying subprocess spawning itself is unsupported on WASI (see the companion issue): the command always fails to exec, and the exec-failure path tries to report 126 or 127. Before this is fixed, that crashes the module with a wasmtime trap like:

Error: failed to run main module `coreutils.wasm`
...
2: exit with invalid exit status outside of [0..126)

instead of a clean, catchable nonzero exit.

Reproduction

$ wasmtime coreutils.wasm nice true
nice: 'true': operation not supported on this platform
Error: failed to run main module `coreutils.wasm`
...
2: exit with invalid exit status outside of [0..126)

Expected

The binary exits cleanly with a nonzero status, without a wasmtime trap.

Activity

  1. oech3 commented on Nov 17, 2026

    @oech3
    Contributor

    Is this something we can fix at upstream instead of here?

  2. eduardomourar commented on Nov 17, 2026

    @eduardomourar
    ContributorAuthor

    It was already brought up in WASI #551 and wasmtime #6919. The problem is that WASI Preview 1 will unlikely to be updated as it is finalized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions