From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 69561@debbugs.gnu.org, alan@idiocy.org
Subject: bug#69561: 30.0.50; Freeze from M-x gnus on macOS
Date: Sat, 09 Mar 2024 12:00:36 +0100 [thread overview]
Message-ID: <m2zfv7y8iz.fsf@Pro.fritz.box> (raw)
In-Reply-To: <86h6hfyaz3.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 09 Mar 2024 12:07:44 +0200")
[-- Attachment #1: Type: text/plain, Size: 2205 bytes --]
Eli Zaretskii <eliz@gnu.org> 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 ;-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ns_select patch --]
[-- Type: text/x-patch, Size: 1057 bytes --]
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
{
next prev parent reply other threads:[~2024-03-09 11:00 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-05 10:59 bug#69561: 30.0.50; Freeze from M-x gnus on macOS Gerd Möllmann
2024-03-05 11:04 ` Gerd Möllmann
2024-03-05 14:29 ` Gerd Möllmann
2024-03-05 15:46 ` Eli Zaretskii
2024-03-05 16:38 ` Gerd Möllmann
2024-03-05 16:52 ` Eli Zaretskii
2024-03-05 17:54 ` Gerd Möllmann
2024-03-07 15:18 ` Gerd Möllmann
2024-03-07 15:52 ` Gerd Möllmann
2024-03-07 16:05 ` Alan Third
2024-03-07 16:30 ` Gerd Möllmann
2024-03-07 16:49 ` Alan Third
2024-03-07 17:01 ` Gerd Möllmann
2024-03-07 18:47 ` Alan Third
2024-03-07 19:29 ` Gerd Möllmann
2024-03-07 20:23 ` Gerd Möllmann
2024-03-08 4:31 ` Gerd Möllmann
2024-03-09 7:33 ` Eli Zaretskii
2024-03-09 9:47 ` Gerd Möllmann
2024-03-09 10:07 ` Eli Zaretskii
2024-03-09 11:00 ` Gerd Möllmann [this message]
2024-03-09 11:11 ` Eli Zaretskii
2024-03-09 11:33 ` Gerd Möllmann
2024-03-09 13:08 ` Eli Zaretskii
2024-03-09 13:21 ` Gerd Möllmann
2024-03-09 13:27 ` Eli Zaretskii
2024-03-09 13:51 ` Gerd Möllmann
2024-03-13 6:11 ` Gerd Möllmann
2024-03-13 16:53 ` Filipp Gunbin
2024-03-13 18:18 ` Gerd Möllmann
2024-03-13 18:20 ` Gerd Möllmann
2024-03-13 19:20 ` Filipp Gunbin
2024-03-13 19:37 ` Gerd Möllmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2zfv7y8iz.fsf@Pro.fritz.box \
--to=gerd.moellmann@gmail.com \
--cc=69561@debbugs.gnu.org \
--cc=alan@idiocy.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.