From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#56487: xgselect race condition leading to abort when USE_GTK not defined Date: Mon, 11 Jul 2022 09:53:22 +0800 Message-ID: <871qus1kkt.fsf@yahoo.com> References: Reply-To: Po Lu Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23290"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.91 (gnu/linux) Cc: 56487@debbugs.gnu.org To: Tom Gillespie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jul 11 03:54:27 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1oAid0-0005vw-BE for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 11 Jul 2022 03:54:26 +0200 Original-Received: from localhost ([::1]:38436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oAicz-0005fZ-28 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Jul 2022 21:54:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oAicc-0005cx-Pk for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2022 21:54:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44156) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oAicc-0004Ol-HP for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2022 21:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oAicc-0004pC-H0 for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2022 21:54:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Jul 2022 01:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56487 X-GNU-PR-Package: emacs Original-Received: via spool by 56487-submit@debbugs.gnu.org id=B56487.165750442018514 (code B ref 56487); Mon, 11 Jul 2022 01:54:02 +0000 Original-Received: (at 56487) by debbugs.gnu.org; 11 Jul 2022 01:53:40 +0000 Original-Received: from localhost ([127.0.0.1]:38053 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oAicG-0004oX-3u for submit@debbugs.gnu.org; Sun, 10 Jul 2022 21:53:40 -0400 Original-Received: from sonic315-21.consmr.mail.ne1.yahoo.com ([66.163.190.147]:42533) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oAicD-0004o5-Ml for 56487@debbugs.gnu.org; Sun, 10 Jul 2022 21:53:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1657504411; bh=Def8Z0A+rD0BIRvc7x++VtiMkHowZ5hy3mNms14rrEU=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=ZGe+mvdt+QxF2G6bhiIZ9WzJJsbLH+wIhKxtX11Vek9NSsBfu+RulC7o8AMZDHOBalqB75YItHYh6u+7+tioxjMWlMuUZFlpfFBVLb9+ZXoE4AzukD/5H7C+wc5YvAhPVX0a0kb586WdE+1pEfz++c+XqKf6fD9QyCTFIYrftfRteSGNyRwO5esAfsyq/SgBAu6zRxPKA0NP/y7qsqj68XWkYQmtSUoa9b42eWN4SwyO4R9IRjLxqKxcU2PtK5+JJBQLio7mZs5lIxWgY+/ia9KrKHw132z+c7rEwmrKdUGMXz1xKCuj90PYah98kVdjP0lpqSAhdQnqWxPnK9ZsEA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1657504411; bh=M7Y5jxmWmYAnJc9DPKojVHcwUPfBvIjzEolNlRli4eU=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=EheJkCbEJFB9gI54ncB5kZRIxmyJTgaPg8nw/yTysFP4lis2dXny1YH8eiLEp3WHXwtZ/6RzZ6PExoCg972iIiWgHWFfHiUTIPLS4oaodXqST+skSj4rctwmlUzQOyY7foA+lkpjNVjZhxeJRugcyg6UUMwBt7a/yYRT5rhTMxVI1+175DtDAPUO8ycogUsk/c5RtrBekkIDsgJkrSmMEjAZezJejPPjSgBaO9U+c8fsbz3njHuNWK10Ih30Pm/0ML3OZA+HK4vcyLwSBJKWBaLJtz498+MNaKFZVB3FuJBtDCTzJFICO2LBt3nqcgeZVvdT2/n8AcBewqaGRb3WgQ== X-YMail-OSG: vt3pYRsVM1mZdSKp43mIqIarVVveA0TAj4RmaAnHzM8gKDI6kNTYo6c3jJIZQMC mwXxVupnwwEt2xORFBdA.J5d0zaglgPddI1Bmx0aRdqfXDRMKn0TzM2DOXzCrbwhB7hhdfM3fkZW RCdD5lrx.HE7B_AqQKOHJkVhinfNrMY3B98rnLtXx8Fn5fRvIIpDZWt1u.komDSy031Gp3oh1jlD 2UXO2.1PH4Hm8l4Ci4k7bREyFXwdvf.XnoH4UK1qciyGlkBitxuWt64th88ckAYsZ_sDCkmlQOG. CEvfyGxq4Pgc9C3Rvgzy6myZhA9ov4ntwdW.J034dV_DtBOMbH1A4gNrXTxzbPZzrQKYO3Q6uW9m 9uCByxXtLK9sPkvwf5LLAv9YjqM43UtPmN2I8ZZlZzKggQQks9gzn1gtOh77aWgiCgs8U4Ex.1zE PTThWMeY14kZ4CrOufrBg0EL90Ah2Mz8jDSqgoxSoQD6zfH_Ef6Bw6Ty3IOePzH5ptAxrKt91_kV uNRCTKyO.wKP6PcYRbtSi2AXNLcsT8JTmbRyxJCU4It8QKNY1i7jaWlQ_zlMjK0VFiZiz8Eu9df4 bYKtaf1847yIBa6wkaE0MyOGwW35tjo1A3W8bzi9YzvA6yhezOG27NeOtQYW6wD2u98_akxlRKKP xoMZ3_nCQwMPuympiPLpAYiBGDyyGHzOaxStZ3CZE2X_twnY7xZZ_rnjlKQufeeaQxeEF1fr4CKj 7kNopNfUVsCPoTqOJwbivoKM95wln1HY_rl9QcRp05CGDC3igYztiYQg3EUqAeLRkitpHBjZs3PQ pXYT_1AD_S0sVRp0Cs3VuTBJJTtHaZDPMOuljEVQIL X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.ne1.yahoo.com with HTTP; Mon, 11 Jul 2022 01:53:31 +0000 Original-Received: by hermes--canary-production-sg3-67975bbd4b-hh5lh (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 01e1a68af9875030d08f6c6f5590b579; Mon, 11 Jul 2022 01:53:26 +0000 (UTC) In-Reply-To: (Tom Gillespie's message of "Sun, 10 Jul 2022 14:05:58 -0700") X-Mailer: WebService/1.1.20381 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:236600 Archived-At: Tom Gillespie writes: > From e120751b9de79be521f490f8c2f99597868b3208 Mon Sep 17 00:00:00 2001 > From: Tom Gillespie > Date: Tue, 5 Jul 2022 13:43:25 -0700 > Subject: [PATCH] xgselect.c: avoid race condition leading to abort > > xgselect.c (xg_select): Remove ifdefs that were previously USE_GTK > specific to be unconditional. This prevents a race condition caused by > a call to release_select_lock from triggering when configuring Emacs > with any toolkit other than gtk. > > xgselect.c (release_select_lock): Add a branch to check whether > threads_holding_glib_lock has gone negative, and if so, restore to zero. > In the case where there are multiple threads, threads_holding_glib_lock > could become and stay negative, prevending g_main_context_release from > ever being called, even when it should have been. > > As far as I can tell the way that the thread.c and xgselect.c code was > written was with the intention of avoiding additional locks. This means > that this code is exquisitely senstivie to slight changes in timing. A > comment in thread.c has been added at one location where this happens. > > It is entirely possible that the removal of the ifdefs branching on > USE_GTK resolves this issue by slightly changing the timings when > using other/no toolkits so that the abort does not trigger. In all > cases aborts can be induced by adding something like fputs in thread.c > at the location of the new comment. > > For the record, the abort behavior is not present in Emacs 27, and was > introduced by 9c62ffb08262c82b7e38e6eb5767f2087424aa47 (the bisect was > quite a pain, so hopefully no one ever needs to do it again). Thanks. The commit message does not really comply with our style, however. The ChangeLog entries should look like this instead: * src/xgselect.c (xg_select): Remove ifdefs that were previously USE_GTK specific to be unconditional. This prevents a race condition caused by a call to release_select_lock from triggering when configuring Emacs with any toolkit other than GTK. (release_select_lock): Add a branch to check whether threads_holding_glib_lock has gone negative, and if so, restore to zero. In the case where there are multiple threads, threads_holding_glib_lock could become and stay negative, prevending g_main_context_release from ever being called, even when it should have been. You can use C-c C-w inside a *vc-log* buffer to generate an appropriately formatted commit message.