`read` on a FIFO whose writer closed blocks where Linux returns 0
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- c, linux, macos
- Área
- backend, operating-systems
Línea de trabajo
Start with sys_read and io_xfer in src/syscall/io.c, then compare how their readiness wait handles a drained FIFO with no writer against the host behavior described here. The issue suggests trying a nonblocking read before waiting or retrying between bounded waits; investigate how either approach preserves guest syscall semantics. Done when the reproducer and FIFO stdin case return EOF instead of hanging, without regressing the pipe behavior noted in the issue.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
What happens
A guest read on a FIFO blocks for good once the last writer has closed and the FIFO is empty. Linux returns 0 (end of file). sys_read in src/syscall/io.c waits for readiness through io_xfer with POLLIN before it reads, and macOS reports nothing for such a FIFO: on the host, poll with POLLIN and a kqueue EVFILT_READ filter both time out on a drained FIFO with no writer, while a plain host read on it returns 0 at once. Linux reports POLLHUP there, so the wait is never reached.
Evidence
elfuse-probe-diff on the probe below, upstream/main a20dfab, Linux 6.18.63:
| side | result |
|---|---|
| Linux | exit 0, bytes=1 last=0 |
| elfuse | killed by the probe's own alarm(3), status 142, no output |
The same happens to a FIFO the shell passes as stdin: build/elfuse <probe> < fifo keeps running after the shell closes the only write end, where host cat < fifo exits.
Cause
Checked on the host side, not by tracing elfuse: after the writer closes and the data is read, macOS poll(POLLIN) returns 0 and a kqueue EVFILT_READ registration returns no event for the FIFO read end, while read returns 0. io_xfer therefore never sees the fd ready and never calls read. A guest pipe is not affected (the fork child in tests/test-registry-stale-pid.c sees EOF on its release pipe).
Reproduce
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
int main(void)
{
char path[] = "/tmp/fifo-eof-XXXXXX";
if (!mkdtemp(path))
return 2;
char f[64];
snprintf(f, sizeof f, "%s/f", path);
if (mkfifo(f, 0600) != 0)
return 2;
pid_t pid = fork();
if (pid == 0) {
int w = open(f, O_WRONLY);
write(w, "x", 1);
usleep(200000);
close(w);
_exit(0);
}
int r = open(f, O_RDONLY);
alarm(3);
char b[8];
ssize_t n, total = 0;
while ((n = read(r, b, sizeof b)) > 0)
total += n;
printf("bytes=%zd last=%zd\n", total, n);
waitpid(pid, NULL, 0);
unlink(f);
rmdir(path);
return 0;
}
Possible fix
Before parking in the readiness wait on a FIFO, try the read once without blocking: read returning 0 with no writer left is end of file and goes back to the guest. Or wait in bounded slices and retry the read between them.
Origin
Found while answering a review on #521: jserv's suggestion to end the hold process on EOF from a FIFO (https://github.com/sysprog21/elfuse/pull/521#discussion_r4558628935) depends on it. Related: #424, #425 (pipe hangup reporting in poll and epoll).
- Lenguaje dominante
- C
- Estrellas
- 287
- Forks
- 33
- Merge medio
- 2 d 17 h
- PR fusionados (30 d)
- 18
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
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 sysprog21/elfuse
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 2 días
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 2 días
Todos los issues de sysprog21/elfuse
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
libreswan/libreswan#3185 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
[SDL3pp] update to 0.12.0Abiertocategory:port-update
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 2 días
-
[InstCombine] 23.x folds 0.0 * (0.0 / x) to 0.0 when x may be zero (fixed on main by #202482)Abiertollvm:instcombine
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
llvm/llvm-project#246503 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día