From owner-freebsd-hackers@freebsd.org Tue Nov 3 23:42:45 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 5FABC467BB5 for ; Tue, 3 Nov 2020 23:42:45 +0000 (UTC) (envelope-from oliver.pntr@gmail.com) Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CQmYJ2sSQz4ckJ; Tue, 3 Nov 2020 23:42:44 +0000 (UTC) (envelope-from oliver.pntr@gmail.com) Received: by mail-yb1-xb2c.google.com with SMTP id a12so16379502ybg.9; Tue, 03 Nov 2020 15:42:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=+Zx5I1TOnfzRp9Qah4GrGLA/AVPm8nDPnchyg9nYrFg=; b=mm5/7DZ+3BhnDrT/LcoRmZDTOnzJlpYbf6gs1sRfqzYml0s0zRr4yIGWgujihBlb8B O2Jeh8AjfYL2RQEcILFEraslzZ/6Dh3L8C57Y9YfBzkl2JkWdDWq9rizOk1U5XRtYz4B RKJRVQwLMMjz9X13002ILXw4a74pVKmqwUWoGP6Wevjci7/t3aNUX1rTOnsZYyQFWeqt U3vsiZ5MCaGFX1mgdU9hY6xQq02agLooznamhDQ3vFTXKKb63FZQ4Jczev0ojcgwL0tj vLU2ATqvs/1I7Y4LVuwVSypBrQESn3aD4bAZqibp2OCOfeDzIzQaK/ZGb4a5/fldmXf9 bQEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=+Zx5I1TOnfzRp9Qah4GrGLA/AVPm8nDPnchyg9nYrFg=; b=eJraDsgroLwiO8NAJZYB3/dXDRFggEth77tQU5piXBxJfxUP0ht4XIQuN1NjQaNM8y XTtJFqqtAT9hW5c3pY+nZ4jTCJry6Rw4Af5D6Pu46lZANQK2QfBr8y+rtm9U7/JBachD Pr4q2P4yv/YSj8S6ooT22d380mtXQ9A16NcNrgmBnAZfmHwo1wJ1iRAeBHz4qR6/Ycww 0NxC/GIxvjhincAq1/JODd00KmMk7cgRgBOUBYUSNtfDMMjobPd3HnSG14z/0ye6vXgv l9Xi94tcPMIn/ic0M20jB5rNwDTfeZ7YWPntW6lwamhaiE5e8MaNEqA25mapMXhryBVV aKfQ== X-Gm-Message-State: AOAM531srVrMcblfzHJcPLcRr429Wz/uejKZSwGto8rhZlTCmiMBVDZR qOQaJY4FAs7I5/2hFqhj9F00/1ArWIVbwc7dhP+4c14v X-Google-Smtp-Source: ABdhPJxsTDqsF8VcHBsiyE4XhX0Ug5ZaqTHVAa8BmzDbo5EB6I8yFJXgfu2YQhfQeglh/Nh0aOdJ5+kD5XjY3lgrTdw= X-Received: by 2002:a25:cc14:: with SMTP id l20mr33382949ybf.478.1604446963139; Tue, 03 Nov 2020 15:42:43 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a25:d8d2:0:0:0:0:0 with HTTP; Tue, 3 Nov 2020 15:42:42 -0800 (PST) In-Reply-To: References: From: Oliver Pinter Date: Wed, 4 Nov 2020 00:42:42 +0100 Message-ID: Subject: Re: poll() POLLHUP behaviour inconsistency To: =?UTF-8?Q?J=C3=A9r=C3=A9mie_Galarneau?= , mjg@freebsd.org Cc: "freebsd-hackers@freebsd.org" , Michael Jeanson X-Rspamd-Queue-Id: 4CQmYJ2sSQz4ckJ X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=mm5/7DZ+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of oliverpntr@gmail.com designates 2607:f8b0:4864:20::b2c as permitted sender) smtp.mailfrom=oliverpntr@gmail.com X-Spamd-Result: default: False [-3.33 / 15.00]; ARC_NA(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; FREEMAIL_FROM(0.00)[gmail.com]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; NEURAL_HAM_LONG(-1.04)[-1.037]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::b2c:from]; NEURAL_HAM_SHORT(-0.29)[-0.287]; NEURAL_HAM_MEDIUM(-1.01)[-1.006]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; TAGGED_FROM(0.00)[]; MAILMAN_DEST(0.00)[freebsd-hackers]; RCVD_COUNT_TWO(0.00)[2] Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.33 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:42:45 -0000 CC: mjg@ On Wednesday, November 4, 2020, J=C3=A9r=C3=A9mie Galarneau < jeremie.galarneau@efficios.com> wrote: > Hi, > > Michael and myself are porting code from Linux to FreeBSD and we have > noticed 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 POLL= HUP'. > > After some head scratching, we figured that on FreeBSD (12.1 and 12.2) if > the > child process died while the parent was not waiting in poll(), we would g= et > 'revents =3D=3D POLLHUP' on the next invocation of poll(), like we do on = Linux. > 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 > events 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 > implicitly. > > 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 > the > 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 t= he > 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 perhap= s > documented?) behaviour. > > Thanks! > J=C3=A9r=C3=A9mie Galarneau > > [1] https://gist.github.com/jgalar/5c3c2673b69fa0df652bda80a88f860c > > -- > J=C3=A9r=C3=A9mie Galarneau > EfficiOS Inc. > http://www.efficios.com > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org= " >