From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Philipp Stephani
Newsgroups: gmane.emacs.devel
Subject: Re: scratch/sigchld-fd 8f0ce42 1/2: Fix deadlock when receiving
SIGCHLD during 'pselect'.
Date: Tue, 19 Jan 2021 19:21:39 +0100
Message-ID:
References: <20210116184947.2105.45267@vcs0.savannah.gnu.org>
<20210116184949.3C17C211A5@vcs0.savannah.gnu.org> <834kjd7yk5.fsf@gnu.org>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
logging-data="2919"; mail-complaints-to="usenet@ciao.gmane.io"
Cc: Philipp Stephani , Emacs developers
To: Eli Zaretskii
Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jan 19 19:57:53 2021
Return-path:
Envelope-to: ged-emacs-devel@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.92)
(envelope-from )
id 1l1wCP-0000e9-2E
for ged-emacs-devel@m.gmane-mx.org; Tue, 19 Jan 2021 19:57:53 +0100
Original-Received: from localhost ([::1]:35950 helo=lists1p.gnu.org)
by lists.gnu.org with esmtp (Exim 4.90_1)
(envelope-from )
id 1l1wCO-0000LF-1S
for ged-emacs-devel@m.gmane-mx.org; Tue, 19 Jan 2021 13:57:52 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47054)
by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.90_1) (envelope-from )
id 1l1vdh-0000E8-Kq
for emacs-devel@gnu.org; Tue, 19 Jan 2021 13:22:03 -0500
Original-Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]:39175)
by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
(Exim 4.90_1) (envelope-from )
id 1l1vdZ-00084X-IZ; Tue, 19 Jan 2021 13:22:01 -0500
Original-Received: by mail-oi1-x231.google.com with SMTP id w124so22202120oia.6;
Tue, 19 Jan 2021 10:21:51 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=rAc+dIDBv+1XUSFwr3Vqy7y7TzC5pqZ7pn7W0vFVOyM=;
b=Hi0q/BgalGcsECc+3ADJyUHZo/1oXcetN0vxCuo4AxRDJRsl4eTd7RHy0QGj5i/PZH
Msf4HQM7xEfCnLIbbHt5Ow+krvb9DbkbY5uUK27YCrAelLu6gtKFspG6i27/CaGWKUTk
UOTi367iXxjb2erv3fW/SFGHbYSPBPGzcRHqECfJ4Dkj8Wfu1yXC9PVYM7sprk6W8nbd
qbddSiRbNiI1FSn+PkKBnFejiFaGaJmyeipOaehN+QwmY6kTsPY+3y9nbtJvVibOidK0
seGmpTSMaTu0yrzeNjwZQvI/GocP0CMqLYsvV/UHadCaCMh1wY2/uW+gXO5wXmX648bP
h4RQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=rAc+dIDBv+1XUSFwr3Vqy7y7TzC5pqZ7pn7W0vFVOyM=;
b=a5hvkCivOgUvkKk8plE6x2CT3LSCch13WEOxs67SDcbEtVjqJI3N/HBfAvKFJcXtL8
mFpszDhKSKu/ft3xBuMEvp4bxApCiifKAlI2Pz3JoKieKRwUwVBCuXAUgPGM/TNezNyA
/Yjvez1lWL9S7KmkHIDsXbPUtqysHV5K4Z3hjfthRtcsXizFFOXphMpog/l91z1qEg4v
1TWL9TFvauuA8FQUijtDPvm8D1yTE8Tu8zT1CyLldGtLAeOhMUrO7QTG6HPfIP7bUGE6
oUxqHJgfogaAED+xsldXyHNmZKWsOh58H+kspEJCdYgzGzYZ0Y627+cxC9u5sHO/rN+Y
j9Yg==
X-Gm-Message-State: AOAM533R8x5CQKWpfhhKxN2gFLXPiaOxUbpFMcdmrb0QV/Ni8sGc1/5I
OGp6tBfR2fxj1OVSZlQg4/cXoOMSK0t0WjNWObbrVH/0o5GUpA==
X-Google-Smtp-Source: ABdhPJwux9qeEq1YP2Xr8XehZstYO8O2YV2OSnsdyychSvj4yU8jbFuXdJGIOot0Oy0KCSZdqVPKY5z2Sf7NifhUNK0=
X-Received: by 2002:aca:b787:: with SMTP id h129mr652281oif.150.1611080510688;
Tue, 19 Jan 2021 10:21:50 -0800 (PST)
In-Reply-To: <834kjd7yk5.fsf@gnu.org>
Received-SPF: pass client-ip=2607:f8b0:4864:20::231;
envelope-from=p.stephani2@gmail.com; helo=mail-oi1-x231.google.com
X-Spam_score_int: -17
X-Spam_score: -1.8
X-Spam_bar: -
X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001,
RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: emacs-devel@gnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: "Emacs development discussions."
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org
Original-Sender: "Emacs-devel"
Xref: news.gmane.io gmane.emacs.devel:263178
Archived-At:
Am Di., 19. Jan. 2021 um 16:09 Uhr schrieb Eli Zaretskii :
>
> > Date: Sat, 16 Jan 2021 13:49:49 -0500 (EST)
> > From: p.stephani2@gmail.com (Philipp Stephani)
> >
> > branch: scratch/sigchld-fd
> > commit 8f0ce42d3eb9b212424a4a25a376287ffc94a73e
> > Author: Philipp Stephani
> > Commit: Philipp Stephani
> >
> > Fix deadlock when receiving SIGCHLD during 'pselect'.
> >
> > If we receive and handle a SIGCHLD signal for a process while waiting
> > for that process, 'pselect' might never return. Instead, we have to
> > explicitly 'pselect' that the process status has changed. We do this
> > by writing to a pipe in the SIGCHLD handler and having
> > 'wait_reading_process_output' select on it.
> >
> > * src/process.c (child_signal_init): New helper function to create a
> > pipe for SIGCHLD notifications.
> > (child_signal_read, child_signal_notify): New helper functions to
> > read from/write to the child signal pipe.
> > (create_process): Initialize the child signal pipe on first use.
> > (handle_child_signal): Notify waiters that a process status has
> > changed.
> > (wait_reading_process_output): Make sure that we also catch
> > SIGCHLD/process status changes.
> >
> > * test/src/process-tests.el
> > (process-tests/fd-setsize-no-crash/make-process): Remove workaround,
> > which is no longer needed.
>
> Philipp, can you please elaborate about this changeset (which was in
> the meantime merged with master)? The comments you added mention some
> kind of deadlock, but don't describe what kind and in which situations
> it could happen, and without that it's hard to understand what
> problem(s) it tries to solve.
I had hoped that the fixed unit test and the commit description would
be clear enough. The issue appears to be that accept-process-output
frequently hangs (doesn't return) even though the process has already
finished. That's what process-tests/fd-setsize-no-crash/make-process
relies on. After some printf debugging, I concluded that
wait_reading_process_output wouldn't be notified about the process
status change in any way, and thus hang forever. A form like (sit-for
0.1) would trigger the process status change to be processed.
>
> In general, pselect is supposed to return with EINTR when SIGCHLD
> happoens while we are inside the call to pselect, and EINTR seems to
> be already handled by wait_reading_process_output. So I wonder why we
> need that additional "self-pipe" to be watched by pselect.
Yes, I'm wondering about that as well, but it's definitely the
behavior I see. Before commiting to master, I ran the test
process-tests/fd-setsize-no-crash/make-process multiple times with and
without the commit, and the outcome was clear: without the commit
accept-process-output would frequently hang, with the commit it never
hangs.
This is pure speculation, but I could imagine multiple things going on:
- Maybe there's no guarantee that pselect actually returns EINTR on SIGCHLD.
- Maybe EINTR is returned too early, before the signal handler got the
chance to update the process status.
>
> In addition, AFAIU this pipe should not be needed on MS-Windows, where
> the pselect emulation waits on the sub-process handles together with
> the other file descriptors, and so gets awakened when a process exits
> or dies. But again, without knowing the exact situations against
> which this changeset tries to protect, it is hard to make a decision.
>
It's definitely not needed on Windows, which has a superior mechanism
anyway (process handles are waitable objects in Windows). I opted to
create the additional pipe on Windows as well - the costs should be
small, and it keeps the code more consistent between the operating
systems.