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

Abierto
#889 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@libsmol ya está trabajando en esto.

Desde el 25/10/2026.

  • #890 de @libsmol — abierto

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

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 + 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.

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de WebAssembly/wasi-libc

Todos los issues de WebAssembly/wasi-libc

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.