From unknown Sun Jun 22 08:11:24 2025 X-Loop: help-debbugs@gnu.org Subject: bug#59055: [PATCH] Fix possible deadlock. Resent-From: Olivier Dion Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 05 Nov 2022 17:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 59055 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch To: 59055@debbugs.gnu.org Cc: Olivier Dion X-Debbugs-Original-To: bug-guile@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.166766759424184 (code B ref -1); Sat, 05 Nov 2022 17:00:02 +0000 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 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-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 unknown Sun Jun 22 08:11:24 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Olivier Dion Subject: bug#59055: closed (Re: bug#59055: [PATCH] Fix possible deadlock.) Message-ID: References: <87wn7p5yt0.fsf@gnu.org> <20221105165923.5426-1-olivier.dion@polymtl.ca> X-Gnu-PR-Message: they-closed 59055 X-Gnu-PR-Package: guile X-Gnu-PR-Keywords: patch Reply-To: 59055@debbugs.gnu.org Date: Sun, 20 Nov 2022 17:20:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1668964802-9115-1" This is a multi-part message in MIME format... ------------=_1668964802-9115-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #59055: [PATCH] Fix possible deadlock. which was filed against the guile package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 59055@debbugs.gnu.org. --=20 59055: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D59055 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1668964802-9115-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit 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. ------------=_1668964802-9115-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit 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 ------------=_1668964802-9115-1-- From unknown Sun Jun 22 08:11:24 2025 X-Loop: help-debbugs@gnu.org Subject: bug#59055: [PATCH] Fix possible deadlock. Resent-From: Olivier Dion Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sun, 20 Nov 2022 18:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59055 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 59055-done@debbugs.gnu.org Received: via spool by 59055-done@debbugs.gnu.org id=D59055.166896925425271 (code D ref 59055); Sun, 20 Nov 2022 18:35:01 +0000 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 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-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