From owner-freebsd-hackers@freebsd.org Tue Nov 3 23:36:13 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0266D467904 for ; Tue, 3 Nov 2020 23:36:13 +0000 (UTC) (envelope-from jeremie.galarneau@efficios.com) Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4CQmPm2FFSz4cKD for ; Tue, 3 Nov 2020 23:36:12 +0000 (UTC) (envelope-from jeremie.galarneau@efficios.com) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 970E62D0E5E for ; Tue, 3 Nov 2020 18:36:11 -0500 (EST) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 7419oMpVzrNf for ; Tue, 3 Nov 2020 18:36:11 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 5F94F2D1031 for ; Tue, 3 Nov 2020 18:36:11 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 5F94F2D1031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1604446571; bh=rv4MYGoTAe2dw3/rUVvL82ndCY8AuSSEeh8DjT4+VlU=; h=MIME-Version:From:Date:Message-ID:To; b=hoenW3EtI/y9m0YDjtTJlRR9s6BtxYNjHgkUrl7UlfYxfHMFkk5WDqes/vNhnlAj5 eyOPbWD7l4cZssgEAsbm3wUaNKvZb3qElm92zu8YsWEsGhVGxMB2pbTe527fAn1BoA 9QtfLuFnmTFozraqOLCLAznKpEy1Z7+m5TPwg1cKr3ghXNoyDL4fOOTH3dGnFrvaVd R7LAuKUFzuESdDmee21QmuqqHxWdchzMQUr3Ansn/lKS2sB9CDaSiDvg9NdjGnPCU1 9HdPos33mVMsiLcoXALJGngV5Y2A8sgRWE+SNTRD/lqJIU5Vk2S2PQpkVZfMWgjdQc fqb243q9CNPkA== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id yPMsrHo14moC for ; Tue, 3 Nov 2020 18:36:11 -0500 (EST) Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by mail.efficios.com (Postfix) with ESMTPSA id 2340C2D1030 for ; Tue, 3 Nov 2020 18:36:11 -0500 (EST) Received: by mail-wr1-f52.google.com with SMTP id s9so20177219wro.8 for ; Tue, 03 Nov 2020 15:36:11 -0800 (PST) X-Gm-Message-State: AOAM533lbHDBDXAOMXDeoV9sDLAMVZliNohEHMb+0VYGQfa4w3a3Q39L 1/ww1NlaYiNEX9uAy0BpGvN5GN23VQa6sLtYzqk= X-Google-Smtp-Source: ABdhPJzhIye0Ji/qFru0p7U6r5PCvuRqI1Lt/ziR9ltFr06ONmz8qJCHkEAY0eoHLcVnh6l3VWEKVCqG+wkxvngR2q8= X-Received: by 2002:adf:de89:: with SMTP id w9mr28492013wrl.212.1604446570120; Tue, 03 Nov 2020 15:36:10 -0800 (PST) MIME-Version: 1.0 From: =?UTF-8?Q?J=C3=A9r=C3=A9mie_Galarneau?= Date: Tue, 3 Nov 2020 18:35:34 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: poll() POLLHUP behaviour inconsistency To: freebsd-hackers@freebsd.org Cc: Michael Jeanson Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4CQmPm2FFSz4cKD X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=efficios.com header.s=default header.b=hoenW3Et; dmarc=pass (policy=none) header.from=efficios.com; spf=pass (mx1.freebsd.org: domain of jeremie.galarneau@efficios.com designates 167.114.26.124 as permitted sender) smtp.mailfrom=jeremie.galarneau@efficios.com X-Spamd-Result: default: False [-2.35 / 15.00]; RCVD_TLS_LAST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[efficios.com:s=default]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; NEURAL_HAM_LONG(-1.05)[-1.045]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; NEURAL_HAM_MEDIUM(-0.97)[-0.972]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[efficios.com:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[efficios.com,none]; NEURAL_HAM_SHORT(-1.00)[-1.003]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; R_MIXED_CHARSET(1.67)[subject]; ASN(0.00)[asn:16276, ipnet:167.114.0.0/17, country:FR]; RCVD_COUNT_SEVEN(0.00)[7]; MAILMAN_DEST(0.00)[freebsd-hackers] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Nov 2020 23:36:13 -0000 Hi, Michael and myself are porting code from Linux to FreeBSD and we have notic= ed a peculiar difference in the way poll() events are handled. In short, we have a process that monitors the lifetime of other processes. = It does so by sharing a pipe between the parent and the child on every fork: read-end in the parent, write-end in the child. The pipe is not used to communicate; it's only used to poll() on the death of the child process. On Linux, poll() is called with a POLLHUP event and nothing else. When the child process dies, the poll() call returns with 'revents =3D=3D POLLHU= P'. After some head scratching, we figured that on FreeBSD (12.1 and 12.2) if t= he child process died while the parent was not waiting in poll(), we would get 'revents =3D=3D POLLHUP' on the next invocation of poll(), like we do on Li= nux. However, if the parent is in poll() when the child dies, the call to poll() never unblocks. This resulted in occasional hangs in the application. I am joining a reproducer [1]. As indicated, changing the 'events' to 'POLLIN | POLLHUP' causes both event= s to be delivered in both cases (child dies before/during calling poll()). The following excerpts of the FreeBSD, Linux, and Open Specification seem in agreement that passing POLLHUP is unnecessary as it is checked implicitl= y. FreeBSD (POLL(2)) This flag is always checked, even if not present in the events bitmask [.= ..] Open Group: This flag is only valid in the revents bitmask; it shall be ignored in th= e events member. Linux (poll(2)): Hang up (only returned in revents; ignored in events). I am surprised by the behaviour being different depending on the moment the child process' death occurs. This is not a big deal for us to work-around, but I would like to know if I should open a bug and try to fix it or if this is intentional (and perhaps documented?) behaviour. Thanks! J=C3=A9r=C3=A9mie Galarneau [1] https://gist.github.com/jgalar/5c3c2673b69fa0df652bda80a88f860c --=20 J=C3=A9r=C3=A9mie Galarneau EfficiOS Inc. http://www.efficios.com