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

From: [email-masked] (Grégoire Jadi)
Date: Mon, 06 Nov 2017 15:20:41 +0100

Hello,

For some time now (emacs-25.1), emacs freezes when I use `org-capture'.
The problem occurs when emacs tries to read the SECONDARY selection.

The following snippet can be used to freeze emacs for 2s everytime on my
computer :
(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))

If the user (me) send any commands (C-p, C-n, M-x, ...) to emacs when it
is frozen, Emacs will stay frozen even after the 2s timeout.
Most of the time, it is possible to recover from the freeze by sending
SIGUSR2 to the emacs process.
The backtrace is :

Debugger entered--Lisp error: (quit)
  x-get-selection-internal(SECONDARY STRING nil nil)
  #f(compiled-function (selection-symbol target-type &optional time-stamp terminal) #<bytecode 0x564065>)(SECONDARY STRING)
  apply(#f(compiled-function (selection-symbol target-type &optional time-stamp terminal) #<bytecode 0x564065>) (SECONDARY STRING))
  gui-backend-get-selection(SECONDARY STRING)
  gui-get-selection(SECONDARY STRING)
  (let ((value 'SECONDARY) (x-selection-timeout 2000)) (gui-get-selection value 'UTF8_STRING) (gui-get-selection value 'COMPOUND_TEXT) (gui-get-selection value 'STRING) (gui-get-selection value 'TEXT))
  eval((let ((value 'SECONDARY) (x-selection-timeout 2000)) (gui-get-selection value 'UTF8_STRING) (gui-get-selection value 'COMPOUND_TEXT) (gui-get-selection value 'STRING) (gui-get-selection value 'TEXT)) nil)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

I've done some experiments :
- Any *single* call of `gui-get-selection' will not freeze emacs for 2s.
- Any *combination of two* calls of `gui-get-selection' will freeze
  emacs for 2s but it will just stops if any command is sent (C-p, C-n,
  ...).
- Any *combination of three or four* calls of `gui-get-selection' will
  freeze emacs for 2s and freeze emacs completely if any command is sent
  (C-p, C-n, ...).
But I've no idea where to look to find out how to fix this problem.
Please, tell me how I can help.

I'm using Emacs 26.0.90 with Gtk3 on OpenBSD 6.2-current (GENERIC.MP).

Best,

In GNU Emacs 26.0.90 (build 1, x86_64-unknown-openbsd, GTK+ Version 3.22.24)
 of 2017-10-29 built on puffy
Repository revision: 6361151a84d643d4a5d658f740dac5809c682704
Windowing system distributor 'The X.Org Foundation', version 11.0.11804000

Configured using:
 'configure --build=amd64-unknown-openbsd --without-sound
 --with-x-toolkit=gtk3 --prefix=/usr/local --sysconfdir=/etc
 --mandir=/usr/local/man --infodir=/usr/local/info --localstatedir=/var
 --disable-silent-rules --disable-gtk-doc 'CFLAGS=-O2 -pipe -fno-pie'
 CPPFLAGS=-I/usr/local/include 'LDFLAGS=-L/usr/local/lib -nopie''

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK DBUS GSETTINGS NOTIFY GNUTLS
LIBXML2 FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 LCMS2

Important settings:
  value of $LC_ALL: en_US.UTF-8
  value of $LC_COLLATE: en_US.UTF-8
  value of $LC_CTYPE: en_US.UTF-8
  value of $LC_MESSAGES: en_US.UTF-8
  value of $LC_MONETARY: en_US.UTF-8
  value of $LC_NUMERIC: en_US.UTF-8
  value of $LC_TIME: en_US.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix