Subject: bug#49253: 27.2; Emacs non-responsive when pasting into terminal-mode

From: Matt Bisson <[email-masked]>
Date: Mon, 28 Jun 2021 10:28:59 -0400

I have observed this behavior from MacOS, with an Emacs running either
locally on MacOS, or over SSH (running on Linux).  Without any
modifications, a -Q invocation causes "xterm--pasted-text: Failed
select: Invalid argument", but without -Q it simply hangs.  It can
attach emacsclient sessions, but they do not accept input.

1. Start "emacs -nw"
2. M-x term <ret>
3. In another application, copy some text into the clipboard, it
doesn't matter what.
4. Return to the Emacs session, and paste into the terminal (I used Command-V).
4a. Emacs no longer responds.  You have to kill (not kill -9, mind
you).  Running strace makes it seem like it's missing some pselect
call, but I haven't quite sniffed out the issue.
4b. With -Q, it  more helpfully prints "xterm--pasted-text: Failed
select: Invalid argument" and continues functioning, but this is
clearly not the desired behavior either.

I no longer have (direct) access to a Linux, XTerm, so I've been
running into the problem since Emacs 26.3 on Linux *through* the Mac
OS Terminal application.  Emacs doesn't have to be the version listed
below, in other words.

I will try to update this bug when I figure out what thing in my dot
file causes the hang instead of the delay+error message.  All I have
relating to terminal-mode is a hook that sets two key-bindings.  When
I manually add this in -Q, it still doesn't hang.  Perhaps it's some
other mode that loads outside my dot file.

This problem is actually super annoying :) as I will have hundreds of
files open, as well as a bunch of terminals in an emacs daemon
process, and accidentally I will forget and paste some text into the
session, at which point I will have to open a second terminal to this
remote host, find and kill the emacs process, then rearrange all my
things back to what I was doing.  It happens once a day at this
point...

In GNU Emacs 27.2 (build 1, x86_64-apple-darwin18.7.0, NS
appkit-1671.60 Version 10.14.6 (Build 18G95))
 of 2021-03-27 built on builder10-14.porkrind.org
Windowing system distributor 'Apple', version 10.3.2022
System Description:  macOS 11.4

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Making completion list...
Quit [2 times]
Making completion list...

Configured using:
 'configure --with-ns '--enable-locallisppath=/Library/Application
 Support/Emacs/${version}/site-lisp:/Library/Application
 Support/Emacs/site-lisp' --with-modules'

Configured features:
NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES
THREADS JSON PDUMPER GMP

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Text

Minor modes in effect:
  global-whitespace-mode: t
  display-battery-mode: t
  show-paren-mode: t
  display-time-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg
epg-config gnus-util rmail rmail-loaddefs text-property-search time-date
subr-x seq gv mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader cl-loaddefs cl-lib sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils disp-table whitespace
battery paren time byte-opt bytecomp byte-compile cconv advice tooltip
eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
term/ns-win ns-win ucs-normalize mule-util term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame minibuffer cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads kqueue cocoa ns
multi-tty make-network-process emacs)

Memory information:
((conses 16 48031 7233)
 (symbols 48 6582 1)
 (strings 32 17172 1862)
 (string-bytes 1 572362)
 (vectors 16 10205)
 (vector-slots 8 127980 10714)
 (floats 8 28 24)
 (intervals 56 200 0)
 (buffers 1000 12))