From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tom Gillespie Newsgroups: gmane.emacs.bugs Subject: bug#56487: xgselect race condition leading to abort when USE_GTK not defined Date: Sun, 10 Jul 2022 20:40:43 -0700 Message-ID: References: <871qus1kkt.fsf@yahoo.com> <87v8s4z6in.fsf@yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33854"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 56487@debbugs.gnu.org To: Po Lu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jul 11 05:42:16 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 1oAkJK-0008eF-Vc for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 11 Jul 2022 05:42:14 +0200 Original-Received: from localhost ([::1]:45908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oAkJJ-0001YZ-Ju for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Jul 2022 23:42:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oAkJ8-0001YR-Ev for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2022 23:42:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44214) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oAkJ8-00033W-5d for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2022 23:42:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oAkJ8-0007XZ-3g for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2022 23:42:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tom Gillespie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Jul 2022 03:42: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.165751086328901 (code B ref 56487); Mon, 11 Jul 2022 03:42:02 +0000 Original-Received: (at 56487) by debbugs.gnu.org; 11 Jul 2022 03:41:03 +0000 Original-Received: from localhost ([127.0.0.1]:38111 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oAkIA-0007W1-Ng for submit@debbugs.gnu.org; Sun, 10 Jul 2022 23:41:03 -0400 Original-Received: from mail-pl1-f176.google.com ([209.85.214.176]:47033) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oAkI8-0007VR-NO for 56487@debbugs.gnu.org; Sun, 10 Jul 2022 23:41:01 -0400 Original-Received: by mail-pl1-f176.google.com with SMTP id l12so3372572plk.13 for <56487@debbugs.gnu.org>; Sun, 10 Jul 2022 20:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BQq/IhS5WMCA5erEgzUX3aF6CUyKEFCtYOK1APcW1wI=; b=UPABnzWIdnAhkdafiM1Pj0clxv8ExB+IOtEvANY79YcgC/+PjQGD7gF3fmn88CwK1a nKJDM9dmAGi3yFpPWxmNEwDa70cLbbngD0YBTsmQcE4hNp2+5Yd9RWRRiKE+SZWtqo2B 6lI88ybN6wtxXU25HxJmYilm1kAL0YxF6UwV2MWncU/D7Xhi2TNX93ET0K4K3r7TCME3 q0tWeV2XwDjwAlNN5IVmDxWd4nxuVFyqRhcGAWPQvfgNLxzsmZPyTvLyX9qpFvHUxW1f Fl3eweQlBr4R3uZnFOI3pfpySKzX2Myf+CBABAHRFinE6qOLLXS9xKBCXnMA8o72Vcm0 hbzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BQq/IhS5WMCA5erEgzUX3aF6CUyKEFCtYOK1APcW1wI=; b=DXTlUro8y3mEtYRKxfXQeLRZbNTP4ifjmifYixNwrkrbyaGA39Wd0xn5jUu3yP79z6 Tv/seTeAQY05QHk15sy3ivw0VWPU/vP3moDo6QmP9Ge+R5IlAo1YbF+4QoACoTpykQnC qGc+rouBShBVt4cUshdNci26r7X0jz53oWaolV8uYtREfITFGsrwTHZVPuEg/axHdp2Q A/gDLLwa/Y1jZz+BlFwCAi74Lbsv27W0JFcK/epbtHeiHlbwbtPenA8W1fP/GvWepNri LbPTc2YAXOIHkekz8RuLgOsXaJ5AfKzCWcbnawdYpNP+hDjNkKMBYEd4Jtg/hH8UxTzR 8vrg== X-Gm-Message-State: AJIora8oVCIxjZbbo6cLoXDeikjVBkWumOkfuA1l1ralSbk6/VYqJFet 2TbbdKeheV7AF4Q3dqlOG2dFHNwpKX332HavvUI= X-Google-Smtp-Source: AGRyM1vmjw/QVdrXr7XuCCZdS02cgytGScvUF3Tpu0zlAH2cELEPXXx+e9WqRYsxzf3BJgh/PNucpKkCdWxfLHGCSq4= X-Received: by 2002:a17:902:7c13:b0:16a:4e69:a5c3 with SMTP id x19-20020a1709027c1300b0016a4e69a5c3mr16621120pll.132.1657510854834; Sun, 10 Jul 2022 20:40:54 -0700 (PDT) In-Reply-To: <87v8s4z6in.fsf@yahoo.com> 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:236604 Archived-At: > 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.