From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Platon Pronko Newsgroups: gmane.emacs.bugs Subject: bug#34821: discard_input_tty does not discard pending input, resulting in garbage inserted into the buffer Date: Tue, 12 Mar 2019 10:53:29 +0300 Message-ID: <6e2317c9-5063-3718-740e-f53c70f5db5b@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------0646CE0A69D45F1D55B1CA10" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="209330"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 To: 34821@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Mar 12 09:12:35 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3cWX-000sGo-DN for geb-bug-gnu-emacs@m.gmane.org; Tue, 12 Mar 2019 09:12:33 +0100 Original-Received: from localhost ([127.0.0.1]:47111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3cWW-0000ju-9v for geb-bug-gnu-emacs@m.gmane.org; Tue, 12 Mar 2019 04:12:32 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:39964) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3cUC-0007Jx-M0 for bug-gnu-emacs@gnu.org; Tue, 12 Mar 2019 04:10:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3cU6-00070e-BN for bug-gnu-emacs@gnu.org; Tue, 12 Mar 2019 04:10:08 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54432) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3cU6-00070Z-45 for bug-gnu-emacs@gnu.org; Tue, 12 Mar 2019 04:10:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1h3cU5-0004eA-PL for bug-gnu-emacs@gnu.org; Tue, 12 Mar 2019 04:10:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Platon Pronko Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 12 Mar 2019 08:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 34821 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.155237818817836 (code B ref -1); Tue, 12 Mar 2019 08:10:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Mar 2019 08:09:48 +0000 Original-Received: from localhost ([127.0.0.1]:39743 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h3cTs-0004db-Fq for submit@debbugs.gnu.org; Tue, 12 Mar 2019 04:09:48 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:53652) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h3cTq-0004dO-LV for submit@debbugs.gnu.org; Tue, 12 Mar 2019 04:09:47 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:39110) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h3cTl-0006mJ-AZ for submit@debbugs.gnu.org; Tue, 12 Mar 2019 04:09:41 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:39421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3cTj-0006j4-Rf for bug-gnu-emacs@gnu.org; Tue, 12 Mar 2019 04:09:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3cEA-0002wI-3v for bug-gnu-emacs@gnu.org; Tue, 12 Mar 2019 03:53:35 -0400 Original-Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]:35553) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3cE9-0002vI-JZ for bug-gnu-emacs@gnu.org; Tue, 12 Mar 2019 03:53:33 -0400 Original-Received: by mail-lf1-x141.google.com with SMTP id h6so1309400lfc.2 for ; Tue, 12 Mar 2019 00:53:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=Kwug2zGxYtX2UQLAbzyLK9fpQ0KWwh4t1DU9NPGGnlA=; b=pMx5z2yZtcbRwW0ILwgR2iDDVT1chW2p6C043KRfuSp2GmjH3ef5BG6j1UqUgSDHqq AfrMljQpBb2Egk/YUCxIWnDAZcAAUM+tZCv336sHO7A1A3HaDXTsxoqLfiq0eB0L6H7I H3GFBUKTOfRgXi1HefaaywG7XjIEO2wOm83PhwuuUo1NwQd7c8kLfDcyMqQ/mtPPzaiT DvXQIamFhcgsvmdDi/7ZWlrzNHjcZhpBFJxmkz9o36vufRDQSIHljPOH/wrwRPilNUwO l7cdFU3EW0q5beRxnmGlGo7K+QnDn/iJEuaN0eH99T9LJpmsd824D3D0Kip881S+JbNu bmAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=Kwug2zGxYtX2UQLAbzyLK9fpQ0KWwh4t1DU9NPGGnlA=; b=CRSae7DxuFVMgyIGe2/IUVmtjbAxcBhLaPut/wXpvJ0+PrJlMwznB90bTnGxPQox3m 6/VWL1BkdjPE7ICXIPaViTDFs9sIYL+8EtN+Mj9AadN69yCq6gBIJQMlgvoqyt5IMVEp Bc4klhh/OvrKDk1EuzVpM3+4Gb6zxfjCXuCyQGY/M6TQLPERSqQN+i5f7Gi8GwB7sHz1 ngJxkWnIv2rSvV86ap7IAUhMj1d6qJN4GgHTMsxiu0B182TrpTjSKhF83DAi9JQUjz+O 4T5kbublIENr15Nr+x/7Ufmod8V0eOF+oS9PCK3hwjhVnB8GaANpT8OWQ1vCEjAT7rBg oolQ== X-Gm-Message-State: APjAAAXVOaYSUkLMBPhRHhtc3+d6w6nmJ2E5JIfBJXhrUVoHgwv7n41L NvRoyh9DXB9qTYgJ3M5QavvNYf6T X-Google-Smtp-Source: APXvYqxuLJWWd5EscdQXEWDvo8TrFQXCWzp4K34cz/V1PR8S2RuLOBTUso9depObF+OpZvVMFVtAiQ== X-Received: by 2002:a19:ec17:: with SMTP id b23mr10601803lfa.76.1552377211461; Tue, 12 Mar 2019 00:53:31 -0700 (PDT) Original-Received: from [192.168.1.65] ([109.252.80.126]) by smtp.gmail.com with ESMTPSA id q22sm1232920ljc.59.2019.03.12.00.53.30 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 00:53:30 -0700 (PDT) Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:156253 Archived-At: This is a multi-part message in MIME format. --------------0646CE0A69D45F1D55B1CA10 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi! Steps to reproduce: 1. Add dummy autosave file (needed for additional delay when starting and reliable bug reproduction): $ touch /tmp/#test.txt# 2. Launch daemon: ./src/emacs -Q --fg-daemon 3. Start the client: ./lib-src/emacsclient -t /tmp/test.txt 4. type 'a' while emacsclient is starting 5. observe "65;5403;1c" inserted at the start of the new file. I hunted for the bug and traced it down to terminal-init-xterm and xterm--query. It makes a "Secondary Device Attributes" query, and expects a response with a specific prefix - but if there were characters waiting in input buffer the handler will never see that prefix, and all the bytes will be sent directly to default keyboard handler and inserted into the buffer. To mitigate the problem xterm--query calls discard-input before sending the query, however for some reason the bytes are still there when read_char is called. I added a workaround in xterm--query, simple `(while (read-event nil nil 0.01))` (see patch attached). Setting `(setq xterm-query-timeout nil)` switches querying to async mode and also helps (the typed character is not discarded that way, which is even better). However, I suspect that the real problem lurks in the discard_tty_input, that for some reason does not actually discard the input - but I'm not sure how to debug it. System details below: In GNU Emacs 27.0.50 (build 27, x86_64-pc-linux-gnu, GTK+ Version 3.24.5)  of 2019-03-12 built on the-big-maker Repository revision: d2270d8fc93b5fb0b82fec4d85d122ea4e38dff3 Repository branch: master System Description: Arch Linux Recent messages: Starting Emacs daemon. test.txt has auto save data; consider M-x recover-this-file When done with a buffer, type C-x # Quit completing-read-default: Command attempted to use minibuffer while in minibuffer Configured features: XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS GLIB NOTIFY INOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM THREADS LIBSYSTEMD JSON PDUMPER LCMS2 GMP Important settings:   value of $LC_TIME: en_SE.UTF-8   value of $LANG: en_US.UTF-8   locale-coding-system: utf-8-unix Major mode: Text Minor modes in effect:   tooltip-mode: t   global-eldoc-mode: t   electric-indent-mode: t   mouse-wheel-mode: t   tool-bar-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   line-number-mode: t   transient-mark-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message rmc puny seq byte-opt gv bytecomp byte-compile cconv dired dired-loaddefs format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg epg-config gnus-util rmail rmail-loaddefs time-date 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 term/xterm xterm server elec-pair mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core term/tty-colors frame 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 minibuffer 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 dbusbind inotify lcms2 dynamic-setting system-font-setting font-render-setting move-toolbar gtk x-toolkit x multi-tty make-network-process emacs) Memory information: ((conses 16 50376 6377)  (symbols 48 6051 1)  (strings 32 15598 1886)  (string-bytes 1 511783)  (vectors 16 7797)  (vector-slots 8 77209 12548)  (floats 8 28 256)  (intervals 56 175 0)  (buffers 992 13)) --------------0646CE0A69D45F1D55B1CA10 Content-Type: text/x-patch; name="xterm--query_discard.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="xterm--query_discard.patch" diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index c4b0a8fb6e..30919988e9 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el @@ -804,6 +804,7 @@ xterm--query ;; Pending input can be mistakenly returned by the calls to ;; read-event below: discard it. (discard-input) + (while (read-event nil nil 0.01)) (send-string-to-terminal query) (while handlers (let ((handler (pop handlers)) --------------0646CE0A69D45F1D55B1CA10--