wasip2/wasip3: reads never see data appended to a file after reaching EOF
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 61/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c
- Ambito
- backend, operating-systems
Direzione di ricerca
Start with libc-bottom-half/sources/file.c, especially file_get_read_stream, __wasilibc_read, and file_seek; compare the wasip2 and wasip3 read paths described in the issue. Reproduce the EOF behavior with the supplied C program under Wasmtime, then check that reads see appended data after EOF and after seeking to the same offset, while the wasip1 behavior remains unchanged.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
On wasm32-wasip2 and wasm32-wasip3, once a read from a file descriptor has reached the end of the file, later reads on that descriptor keep returning 0 after the file has grown, even after an lseek back to the same offset. Seeking to a different offset, or opening a new descriptor, does see the new data. wasm32-wasip1 behaves as expected.
Reproduction
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main(void) {
int writer = open("f.tmp", O_CREAT | O_TRUNC | O_WRONLY, 0600);
int reader = open("f.tmp", O_RDONLY);
char buf[16];
printf("%zd\n", read(reader, buf, sizeof buf)); // 0: the file is empty
write(writer, "one", 3);
printf("%zd\n", read(reader, buf, sizeof buf)); // expected 3, prints 0
lseek(reader, 0, SEEK_SET);
printf("%zd\n", read(reader, buf, sizeof buf)); // expected 3, prints 0
return 0;
}
I see this with wasi-sdk 34 and with main (f6e90063), under Wasmtime 48.0.1 (the version the test suite pins) and Wasmtime 50.0.0.
Cause
file_get_read_stream in libc-bottom-half/sources/file.c keeps the stream returned by read-via-stream in file->read_stream and reuses it for later reads. When that stream reaches the end of the file it reports closed, which __wasilibc_read turns into a 0-byte read, but the closed stream stays cached, so every later read reports end of file again. file_seek only drops the streams when the offset changes, so seeking back to the current offset doesn't reset them either. wasip3 follows the same pattern with file->read.
Impact
- Programs that follow a growing file, such as
tail -f-style loops or Python code reading a log that another process appends to, never see the new data. - SQLite's unix VFS reads pages with
lseek+readon WASI. A second connection that opened a database while it was still empty later fails with "file is not a database" once another connection has written to it.
Proposed fix
I'll open a pull request that drops the read stream when it reports end of file, so the next read opens a new one at the same offset. Happy to take it in a different direction if you'd prefer another approach.
This issue and the accompanying pull request were prepared by an AI coding assistant (Claude Code, running Anthropic's Claude Opus 5.5) on behalf of the libsmol project, which ran into this while running RustPython under Wasmtime. We've tried to verify everything described here, but please let us know if anything looks off or unclear.
- Lingua principale
- C
- Stelle
- 1k
- Fork
- 268
- Merge medio
- 1g 3h
- PR unite (30g)
- 20
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di WebAssembly/wasi-libc
-
wasip2: enabling O_APPEND with fcntl reuses the old positional output stream and overwrites the fileAperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
WebAssembly/wasi-libc#919 ·
I maintainer di solito rispondono entro 1 giorno
-
Contradicting `SOL_TCP` and `SOL_UDP` definition for p1Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
WebAssembly/wasi-libc#855 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
WebAssembly/wasi-libc#815 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
WebAssembly/wasi-libc#809 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
WebAssembly/wasi-libc#778 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di WebAssembly/wasi-libc
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
389ds/389-ds-base#8152 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
isolation2 lockmodes fails on cassert builds: extra AccessShareLock on partition rootForse già presa @tuhaihe l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apache/cloudberry#2356 ·
I maintainer di solito rispondono entro 2 giorni
-
windows-artifacts: the win-arm64 job uses a Visual Studio generator missing from windows-11-armAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
-
documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 91/100