Repository navigation
Description
Problem
WASI providers return negative WASI errno numbers, but portable I/O and sleep loops recognize the POSIX EINTR number (-4). An interrupted WASI read returns -27 immediately instead of retrying.
Starting points: std/sys/wasm/io.wave, std/sys/wasm/time.wave, std/io/fd.wave, std/time/sleep.wave.
Reproduction
Tested at 6257ba3eb4b9f1ab6c247a920c6e0c4b5d699331 on Linux amd64 with LLVM 21.1.8 and a compiler built from that checkout. Build it with LLVM_SYS_211_PREFIX=/usr/lib64/llvm21 cargo build --locked --jobs 2. Node.js 22.22.1 and wasm-ld were used. This is an executed Wave WASI module with controlled host imports, not an assertion about how frequently a production host returns these values.
For a self-contained test against this checkout's std, create a temporary alias (leaving installed std unchanged):
python3 - <<'PYSETUP'
from pathlib import Path
import shutil
p = Path('/tmp/wave-issue-std')
shutil.copytree('std', p, dirs_exist_ok=True)
for f in p.rglob('*.wave'):
f.write_text(f.read_text().replace('"std::', '"checkout_std::'))
PYSETUPSave as repro.wave:
import("checkout_std::io::fd")::{io_read};
pub fun audit() -> i64 { var data: u8 = 0; return io_read(0, &data, 1); }
fun main() -> i32 { return 0; }
target/debug/wavec build repro.wave --dep checkout_std=/tmp/wave-issue-std --target wasm32-wasip1 -O0 --emit=obj --out-dir /tmp/wave-issue-wasi
wasm-ld --no-entry --export=audit --export-memory /tmp/wave-issue-wasi/repro.o -o /tmp/wave-issue-wasi/test.wasmSave as repro.cjs and run node repro.cjs:
const fs = require('fs');
(async () => {
const module = await WebAssembly.compile(fs.readFileSync('/tmp/wave-issue-wasi/test.wasm'));
const imports = {}; let instance; let calls = 0;
for (const i of WebAssembly.Module.imports(module)) {
imports[i.module] ??= {};
imports[i.module][i.name] = () => 0;
}
imports.wasi_snapshot_preview1.fd_read = (fd, vectors, count, output) => {
calls++;
if (calls === 1) return 27;
new DataView(instance.exports.memory.buffer).setUint32(output, 1, true);
return 0;
};
instance = await WebAssembly.instantiate(module, imports);
console.log(String(instance.exports.audit()), 'read calls:', calls);
})().catch(e => { console.error(e); process.exit(1); });Observed: -27 read calls: 1. The success-after-interruption host branch is never reached. Repeat compilation with -O2; the same behavior was observed.
The official WASI Preview 1 header defines EINTR as 27 and timestamps as u64 nanoseconds.
Scope
Align provider and portable-helper error handling for read/write/sleep. Preserve genuine errors and avoid retrying unrelated WASI codes. Decide whether target-aware classification or translation best preserves the current API; do not add libc bindings.
Difficulty: medium.
Completion criteria
- Retry one or multiple interruptions followed by success without losing progress.
- Return permanent errors promptly and retain short-I/O behavior.
- Cover sleep interruption/remaining-duration behavior with controlled host imports.
- Test unrelated WASI errno values so POSIX numeric assumptions cannot cause false retries.
Activity
Stabilize compiler inputs, target ABIs, and freestanding runtimes (#798)