NetBSD Problem Report #60787

From www@netbsd.org  Thu Sep 24 22:00:59 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 6F67A1A923B
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 24 Sep 2026 22:00:59 +0000 (UTC)
Message-Id: <20260924220058.7008E1A923C@mollari.NetBSD.org>
Date: Thu, 24 Sep 2026 22:00:58 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: poll reports socket writable after shutdown(SHUT_WR)
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>

>Number:         60787
>Category:       kern
>Synopsis:       poll reports socket writable after shutdown(SHUT_WR)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 24 22:05:00 +0000 2026
>Closed-Date:    Thu Sep 24 22:06:42 +0000 2026
>Last-Modified:  Thu Sep 24 22:06:42 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current, 11, 10, ...
>Organization:
The PollBSD Shutdown, Inc.
>Environment:
>Description:

	I don't know if there's language in POSIX about this but surely
	it is nonsensical for poll to claim that a socket is writable
	after it has been shut down in the writing direction!

	(This came up while trying to write a test that ensures SIGIO
	is reported in a particular direction, by shutting down writes
	so it won't report POLLOUT any more.)

>How-To-Repeat:
#include <sys/socket.h>

#include <err.h>
#include <poll.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
	int s[2];
	struct pollfd pfd;
	int nfds;

	if (socketpair(AF_LOCAL, SOCK_STREAM, 0, s) == -1)
		err(EXIT_FAILURE, "socketpair");
	if (shutdown(s[0], SHUT_WR) == -1)
		err(EXIT_FAILURE, "shutdown");
	pfd.fd = s[0];
	pfd.events = POLLIN|POLLOUT;
	nfds = poll(&pfd, 1, 0);
	if (nfds == -1)
		err(EXIT_FAILURE, "poll");
	if (nfds == 1 && pfd.fd & (POLLIN|POLLOUT))
		errx(EXIT_FAILURE, "bad");
	return 0;
}

>Fix:

	Yes, please!

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Thu, 24 Sep 2026 22:06:42 +0000
State-Changed-Why:
dup of PR 60786 arising from web server hiccup


>Unformatted:

NetBSD Home
NetBSD PR Database Search

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