From debbugs-submit-bounces@debbugs.gnu.org Sat Nov 05 12:59:54 2022 Received: (at submit) by debbugs.gnu.org; 5 Nov 2022 16:59:54 +0000 Received: from localhost ([127.0.0.1]:57904 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1orMWQ-0006I0-3y for submit@debbugs.gnu.org; Sat, 05 Nov 2022 12:59:54 -0400 Received: from lists.gnu.org ([209.51.188.17]:48268) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1orMWL-0006Hp-Ve for submit@debbugs.gnu.org; Sat, 05 Nov 2022 12:59:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1orMWL-0005tB-Ie for bug-guile@gnu.org; Sat, 05 Nov 2022 12:59:49 -0400 Received: from smtp.polymtl.ca ([132.207.4.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1orMWJ-0004tp-S9 for bug-guile@gnu.org; Sat, 05 Nov 2022 12:59:49 -0400 Received: from laura.ht.home (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 2A5GxXiZ016363 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Sat, 5 Nov 2022 12:59:40 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 2A5GxXiZ016363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1667667580; bh=w4tLj5O8/XRYj8g0dRJLHaRrmfXSg/ED/Ww5QurgW/Q=; h=From:To:Cc:Subject:Date:From; b=uRWF40KMtrhFGd6PUfNYIP7kARgTo2aCNT6YfnKNtOlW7Ivpuq30WkfGQKQmcgvwv Z8guAm5c84P2pFQwhdRu2qXra8Wg+QgSlTtzG/S5NZAY/JYP+A1tAZpR6k5pk0gY7h zaFd7qCIODdTxG6ZIvDlPLxOPJfq9mCPhX8P6UEA= From: Olivier Dion To: bug-guile@gnu.org Subject: [PATCH] Fix possible deadlock. Date: Sat, 5 Nov 2022 12:59:23 -0400 Message-Id: <20221105165923.5426-1-olivier.dion@polymtl.ca> X-Mailer: git-send-email 2.38.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Sat, 5 Nov 2022 16:59:33 +0000 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: Olivier Dion X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) If we got interrupted while waiting on our condition variable, we unlock the kernel mutex momentarily while executing asynchronous operations before putting us back into the waiting queue. However, we have to retry acquiring the mutex before getting back into the queue, otherwise it's possible that we wait indefinitely since nobody could be the owner for a while. * libguile/threads.c (lock_mutex): Try acquring the mutex after signal interruption. --- libguile/threads.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libguile/threads.c b/libguile/threads.c index 280d306bf..0f5cf2ed5 100644 --- a/libguile/threads.c +++ b/libguile/threads.c @@ -1022,14 +1022,7 @@ lock_mutex (enum scm_mutex_kind kind, struct scm_mutex *m, if (err == 0) { - if (scm_is_eq (m->owner, SCM_BOOL_F)) - { - m->owner = current_thread->handle; - scm_i_pthread_mutex_unlock (&m->lock); - return SCM_BOOL_T; - } - else - continue; + goto maybe_acquire; } else if (err == ETIMEDOUT) { @@ -1041,7 +1034,7 @@ lock_mutex (enum scm_mutex_kind kind, struct scm_mutex *m, scm_i_pthread_mutex_unlock (&m->lock); scm_async_tick (); scm_i_scm_pthread_mutex_lock (&m->lock); - continue; + goto maybe_acquire; } else { @@ -1050,6 +1043,14 @@ lock_mutex (enum scm_mutex_kind kind, struct scm_mutex *m, errno = err; SCM_SYSERROR; } + + maybe_acquire: + if (scm_is_eq (m->owner, SCM_BOOL_F)) + { + m->owner = current_thread->handle; + scm_i_pthread_mutex_unlock (&m->lock); + return SCM_BOOL_T; + } } } #undef FUNC_NAME -- 2.38.0 From debbugs-submit-bounces@debbugs.gnu.org Sun Nov 20 12:19:16 2022 Received: (at 59055-done) by debbugs.gnu.org; 20 Nov 2022 17:19:17 +0000 Received: from localhost ([127.0.0.1]:44438 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ownyO-0002Lu-Kk for submit@debbugs.gnu.org; Sun, 20 Nov 2022 12:19:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ownyN-0002Lh-5P for 59055-done@debbugs.gnu.org; Sun, 20 Nov 2022 12:19:16 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ownyH-0006Sp-VL; Sun, 20 Nov 2022 12:19:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=g678kWuoJbgY17yKLKNxvah4dTYbM0oxBIJmwe6VNFo=; b=PtIZ0qfoy9VRtQOeIPBZ pwz+aEFPD7eXpafNNuaVrwvKo9InUnFw4/tGvDunqY7US8rGgKGf2J8Mkecb9fGg8/IEnSTfW/nLl mzrLvjMHj0Hzx2UdKaUHv3kh5zUR0x+dZ43/yC2+cN8wITUY82Zutv9J7BoZmbEM40v5Wgi87a8j0 kEPuszNGddX9MBp7AN0aMqYpSBtWbGzGNaJluuYTckFoE+SeXg9F7ShepQH6KVPCaOr11LFmdh1Z+ bhj+pqK7A57mR3FEOxoSOngVbdztSPTnSyzHEct6ko3ysGGGK4PDymEI3DoSwDf6upeL6VjMTO7zY 52XYsxypJjAUWQ==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201] helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ownyH-0001uJ-Em; Sun, 20 Nov 2022 12:19:09 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Olivier Dion Subject: Re: bug#59055: [PATCH] Fix possible deadlock. References: <20221105165923.5426-1-olivier.dion@polymtl.ca> Date: Sun, 20 Nov 2022 18:19:07 +0100 In-Reply-To: <20221105165923.5426-1-olivier.dion@polymtl.ca> (Olivier Dion's message of "Sat, 5 Nov 2022 12:59:23 -0400") Message-ID: <87wn7p5yt0.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 59055-done Cc: 59055-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi, Olivier Dion skribis: > If we got interrupted while waiting on our condition variable, we unlock > the kernel mutex momentarily while executing asynchronous operations > before putting us back into the waiting queue. > > However, we have to retry acquiring the mutex before getting back into > the queue, otherwise it's possible that we wait indefinitely since > nobody could be the owner for a while. > > * libguile/threads.c (lock_mutex): Try acquring the mutex after signal > interruption. Looks reasonable to me; applied. Did you try to come up with a reproducer? That would be awesome but I guess it=E2=80=99s hard because you need to trigger EINTR at the right poin= t. Thanks, Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Sun Nov 20 13:34:14 2022 Received: (at 59055-done) by debbugs.gnu.org; 20 Nov 2022 18:34:14 +0000 Received: from localhost ([127.0.0.1]:44612 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1owp8w-0006ZW-0h for submit@debbugs.gnu.org; Sun, 20 Nov 2022 13:34:14 -0500 Received: from smtp.polymtl.ca ([132.207.4.11]:44345) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1owp8q-0006ZF-0v for 59055-done@debbugs.gnu.org; Sun, 20 Nov 2022 13:34:12 -0500 Received: from localhost (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 2AKIXubO010837; Sun, 20 Nov 2022 13:34:01 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 2AKIXubO010837 From: Olivier Dion To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: bug#59055: [PATCH] Fix possible deadlock. In-Reply-To: <87wn7p5yt0.fsf@gnu.org> References: <20221105165923.5426-1-olivier.dion@polymtl.ca> <87wn7p5yt0.fsf@gnu.org> Date: Sun, 20 Nov 2022 13:33:56 -0500 Message-ID: <874jutqxuz.fsf@laura> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Sun, 20 Nov 2022 18:33:56 +0000 X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 59055-done Cc: 59055-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On Sun, 20 Nov 2022, Ludovic Court=C3=A8s wrote: > Did you try to come up with a reproducer? That would be awesome but I > guess it=E2=80=99s hard because you need to trigger EINTR at the right po= int. With a stress test in guile-parallel. Very hard to reproduce indeed. You can also reproduce it with `ice-9 futures` I think. Here's the stress test that I've been using: --8<---------------cut here---------------start------------->8--- (use-modules ((ice-9 futures) #:prefix ice-9:) (srfi srfi-1) (srfi srfi-26)) (define (run-stress-test N future touch) (for-each touch (unfold (cut =3D N <>) (lambda (_) (future (const #t))) 1+ 0))) (run-stress-test 10000000 ice-9:make-future ice-9:touch) --8<---------------cut here---------------end--------------->8--- --=20 Olivier Dion oldiob.dev From unknown Fri Aug 15 20:58:15 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 19 Dec 2022 12:24:10 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator