wasip2/wasip3: reads never see data appended to a file after reaching EOF
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 61/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- c
- Área
- backend, operating-systems
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- C
- Estrellas
- 1k
- Forks
- 268
- Merge medio
- 1 d 3 h
- PR fusionados (30 d)
- 20
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de WebAssembly/wasi-libc
-
wasip2: enabling O_APPEND with fcntl reuses the old positional output stream and overwrites the fileAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 70/100
WebAssembly/wasi-libc#919 ·
Los mantenedores suelen responder en 1 día
-
Contradicting `SOL_TCP` and `SOL_UDP` definition for p1Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
WebAssembly/wasi-libc#855 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
MIT licensing state is unhealthyAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
WebAssembly/wasi-libc#815 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
WebAssembly/wasi-libc#809 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
WebAssembly/wasi-libc#778 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
Todos los issues de WebAssembly/wasi-libc
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
389ds/389-ds-base#8152 ·
Los mantenedores suelen responder en 2 días
-
meta:feature-request
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
mpv-player/mpv#18855 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
[FIX]: File Tree in appAbiertobug help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día
-
isolation2 lockmodes fails on cassert builds: extra AccessShareLock on partition rootPosiblemente ocupada @tuhaihe la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
apache/cloudberry#2356 ·
Los mantenedores suelen responder en 2 días