Stream: git-wasmtime

Topic: wasmtime / issue #12913 fd_seek on FIFO returns 0 instead...


view this post on Zulip Wasmtime GitHub notifications bot (Mar 31 2026 at 20:01):

antocuni opened issue #12913:

Test Case

When calling fseek(f, 0, SEEK_END) on a FIFO from a WASI module,
wasmtime returns 0 (success) instead of an error. This makes it impossible to
detect non-seekable streams from within WASI code.

This seems to be a regression: it fails with wasmtime-py 41.0.0, wasmtime-py 42.0.0,
wasmtime CLI 44.0.0, but seems to work with a wasmtime 11.0 which I happened to have around.

The correct return value should be -1, but broken versions return 0.
Native Linux and wasmer 7.1.0 both correctly return -1.

// test_fifo_seek.c
#include <stdio.h>

int main(int argc, char **argv) {
    FILE *f = fopen(argv[1], "r");
    if (!f) { printf("fopen failed\n"); return 1; }
    long cur = ftell(f);
    printf("ftell: %ld\n", cur);
    int r = fseek(f, 0, SEEK_END);
    printf("fseek SEEK_END: %d\n", r);
    printf("ftell after SEEK_END: %ld\n", ftell(f));
    fclose(f);
    return 0;
}

Steps to Reproduce

Compile to WASI (here I'm using zig 0.13.0):

zig cc --target=wasm32-wasi-musl -o test_fifo_seek.wasm test_fifo_seek.c

Run:

mkfifo /tmp/fifo
echo -n "hello" > /tmp/fifo &
wasmtime run --dir /tmp test_fifo_seek.wasm /tmp/fifo

Expected Results

ftell: -1
fseek SEEK_END: -1
ftell after SEEK_END: -1

Actual Results

ftell: 0
fseek SEEK_END: 0
ftell after SEEK_END: 0

Versions and Environment

41.0.0, 42.0.0, 44.0.0

Operating system: Linux (ubuntu)

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Mar 31 2026 at 20:01):

antocuni added the bug label to Issue #12913.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 31 2026 at 21:50):

pchickey assigned pchickey to issue #12913.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 31 2026 at 22:14):

pchickey commented on issue #12913:

Behavior on macos 15 is similar but not identical:

[p.hickey@KVKD0WG7VF:src/repro_12913]% /opt/wasi-sdk-32.0-arm64-macos/bin/wasm32-wasip1-clang test_fifo_seek.c -o test_fifo_seek.wasm
[p.hickey@KVKD0WG7VF:src/repro_12913]% mkdir tmp
[p.hickey@KVKD0WG7VF:src/repro_12913]% echo -n "hello" > tmp/fifo &
[1] 22418
[1]  + done       echo -n "hello" > tmp/fifo
[p.hickey@KVKD0WG7VF:src/repro_12913]% wasmtime run --dir tmp test_fifo_seek.wasm tmp/fifo
ftell: 0
fseek SEEK_END: 0
ftell after SEEK_END: 5

view this post on Zulip Wasmtime GitHub notifications bot (Mar 31 2026 at 22:27):

pchickey commented on issue #12913:

The program's behavior natively on macos and on linux matches the behavior when compiled with the latest wasi-sdk on wasmtime. Thererfore, I am inclined to call wasmtime's behavior correct now, and incorrect on wasmtime 11 and on other runtimes.

Macos 15:

[p.hickey@KVKD0WG7VF:src/repro_12913]% clang test_fifo_seek.c
[p.hickey@KVKD0WG7VF:src/repro_12913]% rm -rf tmp/fifo
tmp/fifo
[p.hickey@KVKD0WG7VF:src/repro_12913]% echo -n "hello" > tmp/fifo &
[1] 29364
[1]  + done       echo -n "hello" > tmp/fifo
[p.hickey@KVKD0WG7VF:src/repro_12913]% ./a.out tmp/fifo
ftell: 0
fseek SEEK_END: 0
ftell after SEEK_END: 5

Ubuntu 24.04:

[ubuntu@sjcstack-dev:~/repro_12913]% clang test_fifo_seek.c
[ubuntu@sjcstack-dev:~/repro_12913]% mkdir tmp
[ubuntu@sjcstack-dev:~/repro_12913]% echo -n "hello" > tmp/fifo &
[1] 65928
[1]  + done       echo -n "hello" > tmp/fifo
[ubuntu@sjcstack-dev:~/repro_12913]% ./a.out tmp/fifo
ftell: 0
fseek SEEK_END: 0
ftell after SEEK_END: 5

view this post on Zulip Wasmtime GitHub notifications bot (Mar 31 2026 at 22:29):

pchickey deleted a comment on issue #12913:

The program's behavior natively on macos and on linux matches the behavior when compiled with the latest wasi-sdk on wasmtime. Thererfore, I am inclined to call wasmtime's behavior correct now, and incorrect on wasmtime 11 and on other runtimes.

Macos 15:

[p.hickey@KVKD0WG7VF:src/repro_12913]% clang test_fifo_seek.c
[p.hickey@KVKD0WG7VF:src/repro_12913]% rm -rf tmp/fifo
tmp/fifo
[p.hickey@KVKD0WG7VF:src/repro_12913]% echo -n "hello" > tmp/fifo &
[1] 29364
[1]  + done       echo -n "hello" > tmp/fifo
[p.hickey@KVKD0WG7VF:src/repro_12913]% ./a.out tmp/fifo
ftell: 0
fseek SEEK_END: 0
ftell after SEEK_END: 5

Ubuntu 24.04:

[ubuntu@sjcstack-dev:~/repro_12913]% clang test_fifo_seek.c
[ubuntu@sjcstack-dev:~/repro_12913]% mkdir tmp
[ubuntu@sjcstack-dev:~/repro_12913]% echo -n "hello" > tmp/fifo &
[1] 65928
[1]  + done       echo -n "hello" > tmp/fifo
[ubuntu@sjcstack-dev:~/repro_12913]% ./a.out tmp/fifo
ftell: 0
fseek SEEK_END: 0
ftell after SEEK_END: 5

view this post on Zulip Wasmtime GitHub notifications bot (Mar 31 2026 at 22:31):

pchickey edited a comment on issue #12913:

Behavior with latest wasi-sdk and on macos 15 is identical:

[p.hickey@KVKD0WG7VF:src/repro_12913]% /opt/wasi-sdk-32.0-arm64-macos/bin/wasm32-wasip1-clang test_fifo_seek.c -o test_fifo_seek.wasm
[p.hickey@KVKD0WG7VF:src/repro_12913]% mkdir tmp
[p.hickey@KVKD0WG7VF:src/repro_12913]% mkfifo tmp/fifo
[p.hickey@KVKD0WG7VF:src/repro_12913]% echo -n "hello" > tmp/fifo &
[1] 22418
[p.hickey@KVKD0WG7VF:src/repro_12913]% wasmtime run --dir tmp test_fifo_seek.wasm tmp/fifo
ftell: 0
fseek SEEK_END: 0
ftell after SEEK_END: 0
[1]  + broken pipe       echo -n "hello" > tmp/fifo

view this post on Zulip Wasmtime GitHub notifications bot (Apr 01 2026 at 01:46):

pchickey commented on issue #12913:

WIP fix: #12922 . That branch currently gets the same results as the host (-1 for all answers) but I still have to write tests for all platforms


Last updated: Apr 12 2026 at 23:10 UTC