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 18:16:36 +0800 Message-ID: <87o7xwymwr.fsf@yahoo.com> References: <871qus1kkt.fsf@yahoo.com> <87v8s4z6in.fsf@yahoo.com> 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="30851"; 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 12:17:41 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 1oAqU1-0007sE-HH for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 11 Jul 2022 12:17:41 +0200 Original-Received: from localhost ([::1]:50306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oAqTz-0007bU-Vl for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 11 Jul 2022 06:17:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oAqTO-0007am-Pc for bug-gnu-emacs@gnu.org; Mon, 11 Jul 2022 06:17:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44483) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oAqTO-0000NE-3x for bug-gnu-emacs@gnu.org; Mon, 11 Jul 2022 06:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oAqTN-0005aQ-Vh for bug-gnu-emacs@gnu.org; Mon, 11 Jul 2022 06:17:01 -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 10:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56487 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 56487-submit@debbugs.gnu.org id=B56487.165753461120993 (code B ref 56487); Mon, 11 Jul 2022 10:17:01 +0000 Original-Received: (at 56487) by debbugs.gnu.org; 11 Jul 2022 10:16:51 +0000 Original-Received: from localhost ([127.0.0.1]:38380 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oAqTD-0005SD-5z for submit@debbugs.gnu.org; Mon, 11 Jul 2022 06:16:51 -0400 Original-Received: from sonic307-56.consmr.mail.ne1.yahoo.com ([66.163.190.31]:46512) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oAqTB-0005ML-D8 for 56487@debbugs.gnu.org; Mon, 11 Jul 2022 06:16:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1657534603; bh=KXfcXy2VdJNLGY4YFpTMptZ2VN9qKklzTtSiMvkmaX4=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=YAyhFfpU5oAb90adx8efNv/N/53tlJcPdahnUWR9vaQl0TrGPr/D3Wn7uXmkZXnkkaan4uS+oDtQH3oQ1jJeqjTbIU9yGnDnOXi2aDut3qeb3KtlaATBkaFoJpHgjmq/UGGx1w8JqDcJALh6nc24P0LsZBA8mxJKpCiqCaz2HkaJKcUS/5vVaKoTgDMwCGq9OBlqLZAyWyjnCWAj3uGy1NTvgtpcATTWYmYk++029k4XBqgD4ghVd29iTUh6QGej2rQZyfpSZ2HWwcOEuNUcnzgWQqACm/v5BwuOIcClZFKMCpipiMxzSEsPfVlIyxBDcTCgW0C+wh4bgqi4Jskh8w== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1657534603; bh=ScJoAeV1v0Htw+MgUfwgmmzAGHpA5WPCRMb1b6e4rhF=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=ahjAUPhGH7jmFcZ7eEYmEbYqcGN0PiAhOJgR5naSdEc752FDdPtJugC/6iPkCHUWF2Tr2GKYRebty0JJqIk3VZriRd2tUzayGzPVVgm6p2plYXpnYK/EHwMLZY9+Px3z53m8NwmQ3h5iu/3UueW0zDByy9C9/gLiiqIv0LDVJ2tZMQvUvZG5SZaLz6TC21ZicXmS3E6MSjkJDbOilnt8y1yk9QcbdrlL5nD+fDmrawjzHnkejvVO/vTfK8pMU96QlwtxaTCoccqnF8gkDHSp5nCNDhw4AeyZ+qENRi5UvWS2C+sPvvhTyMypqOZbwb9/8BX9aPD8bWCbHe51m1mviA== X-YMail-OSG: tTiryDEVM1lOTFQFzGPzRbN44e4Askovc00oWNJNRlMu2PqlP0fjozkZGtUEG47 KCV3wD8S5QOsycyJ2C9qC_qZXZSNg6qxo3oy53aYLpscIhIQc8hBbUzTp29THVF3SiynnCVSjwNd I_htLzymgwB5TG3nSPW1n8vhq8IdTAtFYarZh5OtP_UrEZRBA7bJZ8NMJFZPGC3kwTRBqf3LsOfy DoNZ006Yq8DP6gG70W1Kqa.enIyzFC.MrfuGAR60Y3iLvmVNZuUvZeJZidud_3HSNYNnzrM30t_. xt33s2zLa2m6BZke3GfbwtnyvwuWPI_tnjq.n4H0fSJbocfh0HwV.jkx5iuKQFSmT98DBSB4Y004 1.9ccAcD21WamUaECepW4fFIrzOUuvxoxX0uVTTpMCtBwdp8XW8jQhnu2N2GE.hpWbPKvCxfYmqY WXDe7EV_hjSKnAXYp.n33JsQRKBCCng.a_rlP4OmhTU6aVqWVkjviF2e4VB9dnCxNbGL_Ankqg4a Tj8UQ.eFDRf9Z_S1ecoxYLBWecSpPkjSNIYvzCM.xd_iclNG.ijDs_famF1Zn.3Y1KMstrDBWyth TgWA.BJp8kDV8oGi9tXgqgPEtxkADxYF5fUv4E9TeXU_jv.qNjbURFVxDaW0xjJP0eAgx55F1NQZ .dmAm2_IqkuvYuaibS6o1nq3u15FmH1C4LGY6Fif5h7CDYY8oREabfzl81a8R1iHMQQ7EeqaaeuB 9rvzaL3bvn8gTYoHg8phdUxib_xWGO..kkahX3jhtO.nrVTModNyZZ0RseZ56Wy8Ja4zaBBAd7Ec loDxw13WU6tgSxBRStBz490F1UtispO_xmPKkCMx8K X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic307.consmr.mail.ne1.yahoo.com with HTTP; Mon, 11 Jul 2022 10:16:43 +0000 Original-Received: by hermes--canary-production-sg3-67975bbd4b-v4p6m (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 5c6c0f594010044d1260fc6a81d507cf; Mon, 11 Jul 2022 10:16:40 +0000 (UTC) In-Reply-To: (Tom Gillespie's message of "Sun, 10 Jul 2022 20:40:43 -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:236625 Archived-At: Tom Gillespie writes: >> Thanks. Why did the code previously under !USE_GTK have to be removed? > > When the !USE_GTK code is used an abort in glib will happen > stochastically due to an out-of-sync call to release_select_lock > in thread.c. This happens on my system somewhere between > approximately 1 in 10 and 1 in 10000 times that the test file > is run. > > As far as I can tell from testing there is no difference in behavior > between the USE_GTK and !USE_GTK code. Also, as far as > I can tell from reading, the behavior should be almost identical. > The only addition is to check for already_has_events before > calling thread_select, which may be enough to shift the timing > to prevent a race. > > I have not been able to figure out what the actual underlying > cause is (I tried). All I can say for sure is that there is > something that calls into g_main_context_release and > context->owner_count has a negative overflow to 4294967295. > > I do not think that it is because something somehow sneaks > in between the calls to the atomics in acquire_select_lock > and relese_select_lock. If you would like I can send along > a couple of patches that include changes I made to try to > see what is going on. > > The real underlying issue would seem to be that there is a > missing lock somewhere and that the use of atomics is not > sufficient, but I could be wrong about that. So I suggest that someone find that problem instead. Any attempt to "fix" a race condition by moving code around so that the timings are slightly different is simply deluding oneself. Thanks.