NetBSD Problem Report #60789
From www@netbsd.org Fri Sep 25 15:00:35 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits)
client-signature RSA-PSS (2048 bits))
(Client CN "mail.netbsd.org", Issuer "YR1" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 343121A923C
for <gnats-bugs@gnats.NetBSD.org>; Fri, 25 Sep 2026 15:00:35 +0000 (UTC)
Message-Id: <20260925150034.1AC5B1A923E@mollari.NetBSD.org>
Date: Fri, 25 Sep 2026 15:00:34 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: read on fifo without writer may block
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>
>Number: 60789
>Category: kern
>Synopsis: read on fifo without writer may block
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kern-bug-people
>State: needs-pullups
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Sep 25 15:05:00 +0000 2026
>Closed-Date:
>Last-Modified: Fri Oct 02 03:55:02 +0000 2026
>Originator: Taylor R Campbell
>Release: current, 11, 10, ...
>Organization:
End-of-fifo Blocks and Pipes LLC
>Environment:
>Description:
POSIX sez:
> When attempting to read from an empty pipe or FIFO:
>
> - If no process has the pipe open for writing, read() shall
> return 0 to indicate end-of-file.
https://pubs.opengroup.org/onlinepubs/9799919799/functions/read.html
And that sometimes happens. But sometimes, on a named pipe,
read() blocks instead.
>How-To-Repeat:
barge into a GNU coreutils bug discussion certain that NetBSD
is right _this_ time and walk away with tail between legs
>Fix:
Yes, please!
>Release-Note:
>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/60789 CVS commit: src/tests/lib/libc/sys
Date: Fri, 25 Sep 2026 15:57:31 +0000
Module Name: src
Committed By: riastradh
Date: Fri Sep 25 15:57:31 UTC 2026
Modified Files:
src/tests/lib/libc/sys: t_mkfifo.c
Log Message:
t_mkfifo: New test for consistent read EOF rule.
PR kern/60789: read on fifo without writer may block
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/sys/t_mkfifo.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Thu, 01 Oct 2026 22:47:58 +0000
State-Changed-Why:
fixed in HEAD, needs pullup-11, pullup-10 after the testbed runs
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/60789 CVS commit: src
Date: Thu, 1 Oct 2026 22:45:45 +0000
Module Name: src
Committed By: riastradh
Date: Thu Oct 1 22:45:45 UTC 2026
Modified Files:
src/sys/miscfs/fifofs: fifo_vnops.c
src/tests/lib/libc/sys: t_mkfifo.c
Log Message:
fifo: Fix EOF reporting in various cases.
According to POSIX:
> When attempting to read from an empty pipe or FIFO:
>
> If no process has the pipe open for writing, read() shall
> return 0 to indicate end-of-file.
So:
1. When there are no writers, after open(O_RDONLY|O_NONBLOCK),
blocking reads should immediately report EOF instead of blocking,
and should continue to immediately report EOF on repeated reads.
Previously, they would simply block, because the wrong socket was
initialized with SS_CANTRCVMORE -- though curiously, nonblocking
reads would consistently report EOF.
2. When the last writer has closed, blocking reads should immediately
report report EOF instead of blocking, and should continue to
immediately report EOF on repeated reads.
Previously, the _first_ such read would report EOF, and
_subsequent_ reads would block because we cleared SS_CANTRCVMORE
on the first read.
The old behaviour dates back to 1990 when the fifo_vnops.c code was
first added to the UCB CSRG BSD code in SCCS (without any commit
message):
https://github.com/robohack/ucb-csrg-bsd/commit/1036021a3155e1972e24dae4115eaf0167c4a3fb
This change simply applies FreeBSD's fifo_vnops.c rev. 1.39 by Bruce
Evans from 1997(!):
https://cgit.freebsd.org/src/commit/?id=80987b7a3b0ba57a094d9b5c42af439d5f94fe8f
commit 80987b7a3b0ba57a094d9b5c42af439d5f94fe8f
Author: Bruce Evans <bde@FreeBSD.org>
Date: Sat Dec 13 13:49:59 1997 +0000
Fixed EOF handing.
1. SS_CANTRCVMORE was initially set on the wrong socket, so reads
when there has never been a writer on the socket did not return 0.
Note that such reads are only possible if the fifo was opened in
(O_RDONLY | O_NONBLOCK) mode.
2. SS_CANTSENDMORE was initially set on the wrong socket, but this
was harmless because the wrong socket is never sent from and there
is no need to set the flag initially on the right socket (since open
in (O_WRONLY | O_NONBLOCK) mode fails if there is no reader...).
3. SS_CANTRCVMORE was cleared when read() returns. This broke the
case where read() returns 0 - subsequent reads are supposed to
return 0 until a writer appears. There is no need to clear the
flag when read() returns, since it is cleared correctly when a
writer appears.
PR kern/60789: read on fifo without writer may block
To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/miscfs/fifofs/fifo_vnops.c
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/sys/t_mkfifo.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/60789 CVS commit: src
Date: Fri, 2 Oct 2026 03:53:00 +0000
Module Name: src
Committed By: riastradh
Date: Fri Oct 2 03:53:00 UTC 2026
Modified Files:
src/sys/miscfs/fifofs: fifo_vnops.c
src/tests/lib/libc/sys: t_poll.c
Log Message:
fifo: Followups to fix previous fifo_vnops.c change.
1. Fix open so with O_RDONLY and not O_NONBLOCK, it will block as
POSIX specifies until there are writers -- not until there are
writers _or_ a read is possible without blocking (which is always
immediately true because read will immediately report EOF).
This was a regression in the previous change which I failed to
catch because I committed the change a few days ago to hg and
forgot that I hadn't yet run all the applicable tests when I
exported it to CVS today -- I had only done the background
research and thought about the semantics.
2. Clear xfail on various tests that were fixed by the change.
PR kern/59056: poll POLLHUP bugs
PR kern/60789: read on fifo without writer may block
To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/miscfs/fifofs/fifo_vnops.c
cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libc/sys/t_poll.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.