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

From: Grégoire Jadi <[email-masked]>
Date: Sun, 08 Aug 2021 16:33:48 +0200

Lars Ingebrigtsen <[email-masked]> writes:

Hi,

We (jca@ in Cc is the OpenBSD's maintainer of emacs) finally found a
solution to this bug.  The issue is in the broken SIGIO management.

This option was enabled on OpenBSD in 2011 as a workaround but it is not
required anymore.  We have disabled emacs_broken_SIGIO in OpenBSD's
ports tree and received lots of positive feedbacks (no more hang, some
operations are faster).

So we think it is safe to backport this change upstream.

diff --git a/configure.ac b/configure.ac
index c924634d5b..740f6d79a1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4884,7 +4884,7 @@ AC_DEFUN
 
 case $opsys in
   dnl SIGIO exists, but the feature doesn't work in the way Emacs needs.
-  hpux* | nacl | openbsd | solaris | unixware )
+  hpux* | nacl | solaris | unixware )
     emacs_broken_SIGIO=yes
     ;;
 
Please note that the real issue is not fixed.  The issue is in the
broken SIGIO code itself.  I was able to reproduce the bug by enabling
emacs_broken_SIGIO on Ubuntu LTS 20.04.  I didn't take the time to find
a fix though.

Best,

> <[email-masked]> writes:
>
>> So, I tested it on emacs-27.1 with junk disabled and it still freezes.
>>
>> $ MALLOC_OPTIONS=jj emacs -q
>>
>> (let ((value 'SECONDARY)
>>       (x-selection-timeout 2000))
>>   ;;; from org-get-x-clipboard in lisp/org-compat.el
>>   (gui-get-selection value 'UTF8_STRING)
>>   (gui-get-selection value 'COMPOUND_TEXT)
>>   (gui-get-selection value 'STRING)
>>   (gui-get-selection value 'TEXT))
>
> Thanks for checking.  So it sounds like we do need something like the
> proposed patch (with #ifdef OpenBSD) here, but apparently the patch led
> to other problems.
>
>> I've tested your patch on emacs-25-3.1 and it does prevent the infinite
>> loop. However, if the user sends input to emacs while it is waiting, it
>> raises the following backtrace :
>>
>> Debugger entered--Lisp error: (error "Timed out waiting for reply from
>> selection owner")
>>   x-get-selection-internal(SECONDARY STRING nil nil)
>
> So further work is needed here.  

-- 
gjadi
PGP : AF26 E9C2 A1C8 8D32 A868  4386 1373 5477 2B65 1894