Subject: bug#32986: 27.0.50; unexpected delay in while-no-input + accept-process-output

From: João Távora <[email-masked]>
Date: Mon, 08 Oct 2018 11:48:01 +0100

Hello maintainers,

I've asked this in Emacs devel already:
https://lists.gnu.org/archive/html/emacs-devel/2018-10/msg00037.html. Someone
suggested I report it as a bug.  It happens Windows (machine of bug
report), but also on my Ubuntu virtual server.

I would expect while-no-input to break out of accept-process-output very
quickly after user keyboard input.  These expectations are met except
for some situations.  Here's some test code:

   (defmacro joaot/time (&rest body)
     `(let ((start (current-time)))
        (prog1
            (progn ,@body)
          (let ((msg (format "Took %s seconds and returned "
                             (format-time-string
                              "%S.%3N"
                              (time-subtract (current-time) start)))))
            (if current-prefix-arg
                (insert "; " msg)
              (message msg))))))

Now, after each of these, I'm pressing C-u C-x C-e SPC as fast as I can.
The second result is unexpected, all the others are fine. Moreover, it
varies from 0.7s to as much as 5s.  

    (joaot/time
     (while-no-input
       (while t (accept-process-output nil 0.05)))); Expected, took 00.201 seconds and returned t 
     
    (joaot/time
     (while-no-input
       (while t (accept-process-output nil 30)))); Took 02.694 seconds and returned t 
     
    (joaot/time
     (while (sit-for 30))); Took 00.126 seconds and returned nil 
     
    (joaot/time
     (while (sit-for 0.1))) ; Took 00.093 seconds and returned nil

I tried quickly pluggin GDB in at the right time, but I don't know if
I'm using the right GDB (using msys's which is pretty slow) and I
probably should be using an unoptimized Emacs.  Anyway, as a start this
is what "bt full" look like:

   (gdb) bt full
   #0  0x00007ffc97b0d8c1 in ntdll!DbgBreakPoint () from /c/WINDOWS/SYSTEM32/ntdll.dll
   No symbol table info available.
   #1  0x00007ffc97b39a0b in ntdll!DbgUiRemoteBreakin () from /c/WINDOWS/SYSTEM32/ntdll.dll
   No symbol table info available.
   #2  0x00007ffc952b3034 in KERNEL32!BaseThreadInitThunk ()
      from /c/WINDOWS/System32/KERNEL32.DLL
   No symbol table info available.
   #3  0x00007ffc97ae1461 in ntdll!RtlUserThreadStart () from /c/WINDOWS/SYSTEM32/ntdll.dll
   No symbol table info available.
   #4  0x0000000000000000 in ?? ()
   No symbol table info available.
   Backtrace stopped: previous frame inner to this frame (corrupt stack?)
   (gdb) xbacktrace
   Undefined command: "xbacktrace".  Try "help".

xbacktrace probably failed because of some Python error loading .gdbinit

In GNU Emacs 27.0.50 (build 1, x86_64-w64-mingw32)
 of 2018-10-02 built on GONDOMAR
Repository revision: dfbb207ff946792efebb31c0c59b8245c304544a
Windowing system distributor 'Microsoft Corp.', version 10.0.17134
System Description: Microsoft Windows 10 Pro (v10.0.1803.17134.286)

Recent messages:
joaot/time
Quit
Mark set
Quit
Mark set
Is this a siscog mail? (y or n) n
Quit [4 times]
Mark set [2 times]
Auto-saving...done
Type C-x 1 to delete the help window.
Quit [3 times]
Configured using:
 'configure --prefix=/c/emacs/emacs-26 --without-imagemagick
 --without-dbus'

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB
TOOLKIT_SCROLL_BARS THREADS JSON LCMS2 GMP

Important settings:
  value of $LC_CTYPE: en_US.UTF-8
  value of $LANG: PTG
  locale-coding-system: cp1252

Major mode: Message

Minor modes in effect:
  gnus-message-citation-mode: t
  diff-auto-refine-mode: t
  savehist-mode: t
  winner-mode: t
  ido-everywhere: t
  electric-pair-mode: t
  delete-selection-mode: t
  global-auto-revert-mode: t
  show-paren-mode: t
  mml-mode: t
  company-quickhelp-mode: t
  company-quickhelp-local-mode: t
  global-aggressive-indent-mode: t
  shell-dirtrack-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  auto-fill-function: message-do-auto-fill
  transient-mark-mode: t
  abbrev-mode: t

Load-path shadows:
Error during checking
Features:
(shadow emacsbug darkroom face-remap gnus-dup flymake-cc
display-line-numbers autoload trace imenu ...)

Memory information:
((conses 16 944904 133288)
 (symbols 56 54804 49)
 (strings 32 196879 15626)
 (string-bytes 1 4881114)
 (vectors 16 98591)
 (vector-slots 8 2249333 86252)
 (floats 8 863 1865)
 (intervals 56 47943 2025)
 (buffers 992 132))