From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id iC3nOnZdlmB7XgAAgWs5BA (envelope-from ) for ; Sat, 08 May 2021 11:44:22 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 6OGLNnZdlmDveQAAB5/wlQ (envelope-from ) for ; Sat, 08 May 2021 09:44:22 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 648DE2FAA6 for ; Sat, 8 May 2021 11:44:22 +0200 (CEST) Received: from localhost ([::1]:44324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lfJVV-0002ZD-Jf for larch@yhetil.org; Sat, 08 May 2021 05:44:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50378) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lfJVC-0002Yq-Hv for bug-guix@gnu.org; Sat, 08 May 2021 05:44:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37597) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lfJVC-0004qC-8B for bug-guix@gnu.org; Sat, 08 May 2021 05:44:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lfJVC-0002Yj-6e for bug-guix@gnu.org; Sat, 08 May 2021 05:44:02 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#41948: Shepherd deadlocks Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Sat, 08 May 2021 09:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41948 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Mathieu Othacehe Received: via spool by 41948-submit@debbugs.gnu.org id=B41948.16204669999816 (code B ref 41948); Sat, 08 May 2021 09:44:02 +0000 Received: (at 41948) by debbugs.gnu.org; 8 May 2021 09:43:19 +0000 Received: from localhost ([127.0.0.1]:49141 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lfJUV-0002YG-2X for submit@debbugs.gnu.org; Sat, 08 May 2021 05:43:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39942) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lfJUT-0002Y7-BQ for 41948@debbugs.gnu.org; Sat, 08 May 2021 05:43:18 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:55898) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lfJUO-0004It-4U for 41948@debbugs.gnu.org; Sat, 08 May 2021 05:43:12 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=60316 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lfJUL-0001K0-Sx; Sat, 08 May 2021 05:43:12 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <87h7v75txx.fsf@gnu.org> <87a70yc9kj.fsf@gnu.org> <87k0xyhq22.fsf@gnu.org> Date: Sat, 08 May 2021 11:43:07 +0200 In-Reply-To: <87k0xyhq22.fsf@gnu.org> (Mathieu Othacehe's message of "Sun, 16 Aug 2020 11:56:37 +0200") Message-ID: <87im3ta7dg.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 41948@debbugs.gnu.org Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1620467062; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post; bh=T0vxKbdr+fIl50dzXr+dWnp1x7iQPdf1LI3FF1TQEIs=; b=LtcD2vX8pNPyPZ79wgy2uaiVEhTBOqoJgFexsYeOQPHnKKOczJ1ez/49ReW5BYxPlsRGAc 7FZ2T8BwnZJkIIXsECro3xXW/jptT3B3Gbqh4BT7Yh7EuY4SLzONKUcBYRYQfEqu63WWL+ 986FtxhxIIkCWtMPBQRSft+SiUSKA+N6q3nioXdQcJhA/ga0fC6sYbhVT80qXGv9FRz5Y9 nFXWg/wLdYNj7EUAYV6kB8GKgCCV9yAtj4i30NuerTLmS8aKElPuSCLbVu+jCePsnxTz2i lUOnnzYT+phsvD3gNAlmemx4g8BesGUK8Nqf8gIfSXoskYLsqi6a8riAEEpwTQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1620467062; a=rsa-sha256; cv=none; b=SbIPbLmV0mARCw+4pr6Z8bMhGQ6vd6sQNC3GB+tHytV6F/i+0Ny6Bg2LbIMxoRXjE4Cfeb mQaYi4UODi4lHMI59H34ZKO34gSkkjAXYbDCrzK9YMvdt/qhtrf28ZftaH2ukG8giPOGvT +qdZg1bgAPdwgKbmhhHvq2An9h28ofTRswsl9T4f8PUk0+pOU3mxd1prTQ/i3s5+F/1gJ/ R+uxTyvaWgpKO25fHU9dhnugd0zRfiPG/2U7D90Gh4WWdFL4qkA79iaG5ctcvEVcoXFPYd gFLhtAOJRuuaAODBciHXvYmhMl2BIY9Ru79EpR1QSKnLPZJzL2JaWZSBTDgu2g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Spam-Score: -2.95 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Queue-Id: 648DE2FAA6 X-Spam-Score: -2.95 X-Migadu-Scanner: scn0.migadu.com X-TUID: P8KNdIv33PAp --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, Mathieu Othacehe skribis: > Those two finalizer threads share the same pipe. When we try to > stop the finalizer thread in Shepherd, right before forking a new > process, we send a '\1' byte to the finalizer pipe. > > 1 write(6, "\1", 1 > > > which is received by (line 183597):=20 > > 253 <... read resumed>"\1", 1) =3D 1 > > the marionette finalizer thread. Then, we pthread_join the Shepherd > finalizer thread, which never stops! Quite unfortunate. And here=E2=80=99s the patch for this pipe: it closes the finalizer pipe pre-fork, and it gets reopened lazily. Together with the =E2=80=98sleep_pipe=E2=80=99 patch, it appears to fix the= problems described here. Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/libguile/finalizers.c b/libguile/finalizers.c index 0ae165fd1..5ddc7dbef 100644 --- a/libguile/finalizers.c +++ b/libguile/finalizers.c @@ -24,6 +24,7 @@ # include #endif +#include #include #include #include @@ -170,7 +171,7 @@ queue_finalizer_async (void) #if SCM_USE_PTHREAD_THREADS -static int finalization_pipe[2]; +static int finalization_pipe[2] = { -1, -1 }; static scm_i_pthread_mutex_t finalization_thread_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER; static pthread_t finalization_thread; @@ -254,6 +255,13 @@ start_finalization_thread (void) scm_i_pthread_mutex_lock (&finalization_thread_lock); if (!finalization_thread_is_running) { + assert (finalization_pipe[0] == -1); + + if (pipe2 (finalization_pipe, O_CLOEXEC) != 0) + scm_syserror (NULL); + + GC_set_finalizer_notifier (notify_finalizers_to_run); + /* Use the raw pthread API and scm_with_guile, because we don't want to block on any lock that scm_spawn_thread might want to take, and we don't want to inherit the dynamic state (fluids) of the @@ -276,6 +284,12 @@ stop_finalization_thread (void) notify_about_to_fork (); if (pthread_join (finalization_thread, NULL)) perror ("joining finalization thread"); + + close (finalization_pipe[0]); + close (finalization_pipe[1]); + finalization_pipe[0] = -1; + finalization_pipe[1] = -1; + finalization_thread_is_running = 0; } scm_i_pthread_mutex_unlock (&finalization_thread_lock); @@ -284,7 +298,6 @@ stop_finalization_thread (void) static void spawn_finalizer_thread (void) { - GC_set_finalizer_notifier (notify_finalizers_to_run); start_finalization_thread (); } @@ -368,8 +381,6 @@ scm_set_automatic_finalization_enabled (int enabled_p) if (enabled_p) { #if SCM_USE_PTHREAD_THREADS - if (pipe2 (finalization_pipe, O_CLOEXEC) != 0) - scm_syserror (NULL); GC_set_finalizer_notifier (spawn_finalizer_thread); #else GC_set_finalizer_notifier (queue_finalizer_async); @@ -381,10 +392,6 @@ scm_set_automatic_finalization_enabled (int enabled_p) #if SCM_USE_PTHREAD_THREADS stop_finalization_thread (); - close (finalization_pipe[0]); - close (finalization_pipe[1]); - finalization_pipe[0] = -1; - finalization_pipe[1] = -1; #endif } @@ -423,10 +430,6 @@ scm_init_finalizer_thread (void) { #if SCM_USE_PTHREAD_THREADS if (automatic_finalization_p) - { - if (pipe2 (finalization_pipe, O_CLOEXEC) != 0) - scm_syserror (NULL); GC_set_finalizer_notifier (spawn_finalizer_thread); - } #endif } --=-=-=--