From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Newsgroups: gmane.emacs.bugs Subject: bug#69561: 30.0.50; Freeze from M-x gnus on macOS Date: Sat, 09 Mar 2024 12:00:36 +0100 Message-ID: References: <864jdfzwnw.fsf@gnu.org> <86h6hfyaz3.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24185"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 69561@debbugs.gnu.org, alan@idiocy.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 09 12:02:54 2024 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 1riuTc-00062x-7x for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 09 Mar 2024 12:02:52 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riuTI-0003UM-DI; Sat, 09 Mar 2024 06:02:32 -0500 Original-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 1riuTG-0003Ts-9K for bug-gnu-emacs@gnu.org; Sat, 09 Mar 2024 06:02:30 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riuTG-0001hQ-0Z for bug-gnu-emacs@gnu.org; Sat, 09 Mar 2024 06:02:30 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1riuTm-0007Me-CM for bug-gnu-emacs@gnu.org; Sat, 09 Mar 2024 06:03:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 09 Mar 2024 11:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69561 X-GNU-PR-Package: emacs Original-Received: via spool by 69561-submit@debbugs.gnu.org id=B69561.170998214128251 (code B ref 69561); Sat, 09 Mar 2024 11:03:02 +0000 Original-Received: (at 69561) by debbugs.gnu.org; 9 Mar 2024 11:02:21 +0000 Original-Received: from localhost ([127.0.0.1]:60780 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1riuT6-0007Lb-VB for submit@debbugs.gnu.org; Sat, 09 Mar 2024 06:02:21 -0500 Original-Received: from mail-ed1-f47.google.com ([209.85.208.47]:46363) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1riuT3-0007LH-1A for 69561@debbugs.gnu.org; Sat, 09 Mar 2024 06:02:20 -0500 Original-Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5658082d2c4so3755039a12.1 for <69561@debbugs.gnu.org>; Sat, 09 Mar 2024 03:01:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709982038; x=1710586838; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=0k7hB41h/AKN2ZANFjBMn2v5YZ52VzfDlYzitdZtMxQ=; b=OoX/VcJkWVY/efvAfnVJhIcAWo1/1eq95WpXJjJsj0DuxkUTYBg6dYztoh5/906lS9 ffuLTDIt8qRGtt7v45SPfMfNcdZIsBFAQJa/L24Z6dyq85gEEORhzCr6n6wZmPk+aR9D ye78M+3+Kwq4AAnOBQ9W+nm6HarPWzcwby1CGJWFbFx+SGgRu6bSXamkd6sLcPW4O47K LbMGhXbsp6VC37NC6Ur18QgItugZkXuhjfNLfylQzE7pcBxJj51yH2IQY2rop48uOsK3 +yI+TJzxCnM0rM8AVCsFsQrPezggydNqkvJJq7TtfKdJSq9qmSf/HhCne7KV38KhC7eO tuQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709982038; x=1710586838; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0k7hB41h/AKN2ZANFjBMn2v5YZ52VzfDlYzitdZtMxQ=; b=Cuq23D8hxx4H+zExlv7FYtL0VkQUvxY416+OK7NagSkWk5nVkrQwfBtah+Mum3H/fa VWCwXWlmhDefjZJZpxQg+5xdXsORV6cGWaTbLm1fqExR2xKCyr8HDz1rO/WFyLkjFdnI aic015LjNjIr0wRURhUQWHc0n8PNhIbSz1IY5zkB6KGk+sW0YyZamVPHNV2HYzZWdTTD 2dieLTlkZjXPNcSyVCx72K4XZQV1eVCPduIJ/oB+GyS/AfXoazdQ0Kfqnf67KGMVsd3l Gxw/gdF/rsEF7GTk3V0+NWeCYWAukLRmJ1X05FCHehmBEccndllPV63lT6whlSbgmvgJ gMNw== X-Forwarded-Encrypted: i=1; AJvYcCW3Wxvnos/T7dRAmGjT+T/51/WgFRJwf0B6R+29LJOVW5XTyt2dgshiOleBbUanYj3fsqQbMVOjo/keWRqv9sWDOAsO2yA= X-Gm-Message-State: AOJu0YzhKGjpOYQKzgznrDk9xS2nUCBjuQCP0cQQTqoZT2TbeDm/okKF LbHWCi3Bpw3wk0tUs3BvVUbsIiKa53ib+1AsSeHnKaKccsVnY6REd+tdriBA X-Google-Smtp-Source: AGHT+IF5mBLDS82OtVg2hW9ZC4FV4W8B9EyHD1pMHkuRXHFhVsPBS8Z9sRowbVJmuhjPaE4UMN9bZA== X-Received: by 2002:a17:906:f902:b0:a41:315b:94d9 with SMTP id lc2-20020a170906f90200b00a41315b94d9mr676047ejb.71.1709982038149; Sat, 09 Mar 2024 03:00:38 -0800 (PST) Original-Received: from Pro.fritz.box (p4fe3a846.dip0.t-ipconnect.de. [79.227.168.70]) by smtp.gmail.com with ESMTPSA id s12-20020a1709066c8c00b00a3ee9305b02sm771189ejr.20.2024.03.09.03.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 03:00:37 -0800 (PST) In-Reply-To: <86h6hfyaz3.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 09 Mar 2024 12:07:44 +0200") 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:281327 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> Any idea how to proceed with this, Eli and Alan? > > I'm afraid I've lost the relevant context. Can you remind why Emacs > is not responsive? does it infloop somewhere, and if so, where? Yes, it loops in wait_reading_process_out, which calls ns_select without making progress, and without handling NS events, which is the reason why the system says Emacs is unresponsice (beach ball of death). This can happen in various circumstances. I have seen freezes in epg (decrypting autoinfo), flymake, json-rps (eglot + clangd) so far. And it started to get really bad lately in master, for unknown reasons. My analysis, all the usual disclaimers apply ;-)... The NS port event handling works like so: NS has a queue named hold_events_q of struct input_event (global variable). The queue is filled when EmacsView receives NS events from the system. NS events are processed by calling [NSApp run] with some ornamention around it to make sure the call returns. ns_select and ns_read_socket do that. The input_events in hold_events_q are given to Emacs in ns_read_socket, which is installed for terminal type as read_socket_hook. That's how normally a C-g is recognized by kdb_store_event and Vquit_flag is set. But hold_events_q are _not_ kbd_store'd in ns_select. Instead we have if (hold_event_q.nr > 0 && !run_loop_only) { /* We already have events pending. */ raise (SIGIO); errno = EINTR; return -1; } So, ns_select returns -1 to wait_reading_process_output which loops, AFAICT. By immediately returning -1 in ns_select it additionally also does not run [NSApp run], which means NS/Cocoa events will not be processed. If nobody else (ns_read_socket, for instance) is called in from somehwere we're stuckin 2 ways: - Existing input_events in hold_event_q are never transferred to the rest of Emacs. - NS events are never processed, which leads to the beach ball. So, I tried the attached patch to ns_select, which does 2 things: - it makes sure that hold_event_q input_events are transferred to Emacs. - it makes sure that [NSApp run] is always called. Not that I really know what I'm doing, but it seems to work ;-) --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ns_select.patch Content-Description: ns_select patch diff --git a/src/nsterm.m b/src/nsterm.m index f094b145fe3..075d1af0938 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -4739,12 +4739,13 @@ Function modeled after x_draw_glyph_string_box (). check_native_fs (); #endif - if (hold_event_q.nr > 0 && !run_loop_only) + /* If there are input events pending, store them so that + Emacs can recognize C-g. */ + if (hold_event_q.nr > 0) { - /* We already have events pending. */ - raise (SIGIO); - errno = EINTR; - return -1; + for (int i = 0; i < hold_event_q.nr; ++i) + kbd_buffer_store_event_hold (&hold_event_q.q[i], NULL); + hold_event_q.nr = 0; } eassert (nfds <= FD_SETSIZE); @@ -4757,7 +4758,7 @@ Function modeled after x_draw_glyph_string_box (). if (NSApp == nil || ![NSThread isMainThread] || (timeout && timeout->tv_sec == 0 && timeout->tv_nsec == 0)) - return thread_select (pselect, nfds, readfds, writefds, + thread_select (pselect, nfds, readfds, writefds, exceptfds, timeout, sigmask); else { --=-=-=--