wasip2/wasip3: reads never see data appended to a file after reaching EOF

Aperta
#889 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@libsmol ci sta già lavorando.

Dal 25/10/2026.

  • #890 di @libsmol — aperta

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

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 + read on 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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di WebAssembly/wasi-libc

Tutte le issue di WebAssembly/wasi-libc

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.