Subject: bug#29170: 26.0.90; Emacs freezes when capturing an org-template

From: Lars Ingebrigtsen <[email-masked]>
Date: Fri, 02 Oct 2020 16:30:45 +0200

Eli Zaretskii <[email-masked]> writes:

> Can you debug the cause which causes the freeze?  What is the code
> that freezes?

I haven't debugged it, but Manuel said previously in this thread that
the following patch sort of fixes the problem (included below), but it
then leads to other issues.

But the problem is in that area, I take it.

-----

Here is a patch against HEAD to avoid the hang in infinite loop. The
'x-selection-timeout' pause will still be there even with this patch.

My understandings:

On OpenBSD, most of the time, the function
"xselect.c/x_get_foreign_selection" won't get a SelectNotify with
(SECONDARY, TEXT) as arguments (that I did not understand and it might
never happen on other oses).

But then, while waiting at most 'x-selection-timeout' into
"process.c/wait_reading_process_output" the 'now' variable won't have a
chance of being invalidated or updated and that is what cause the
infinite loop.

Someone more knowledgeable of "process.c/wait_reading_process_output"
might have a better solution to this problem.

diff --git a/src/process.c b/src/process.c
index fc46e74332..25bd28a82b 100644
--- a/src/process.c
+++ b/src/process.c
@@ -5115,8 +5115,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
       /* Exit if already run out.  */
       if (wait == TIMEOUT)
 	{
-	  if (!timespec_valid_p (now))
-	    now = current_timespec ();
+	  now = current_timespec ();
 	  if (timespec_cmp (end_time, now) <= 0)
 	    break;
 	  timeout = timespec_sub (end_time, now);

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no