Subject: bug#22344: closed (Re: bug#22344: 25.0.50 (and 24.5.1, 24.4); Sending 4097 bytes to a subprocess hangs Emacs on Windows 8 and 10)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 14 Jan 2016 18:06:02 +0000

Your bug report

#22344: 25.0.50 (and 24.5.1, 24.4); Sending 4097 bytes to a subprocess hangs Emacs on Windows 8 and 10

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
22344: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=22344
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#22344: 25.0.50 (and 24.5.1, 24.4); Sending 4097 bytes to a subprocess hangs Emacs on Windows 8 and 10
From: Eli Zaretskii <[email-masked]>
To: [email-masked]
Cc: [email-masked]
Date: Thu, 14 Jan 2016 20:05:40 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> Date: Thu, 14 Jan 2016 17:36:28 +0100
> From: Benjamin Schwehn <[email-masked]>
> Cc: [email-masked]
> 
> > Thanks for testing.  It is important that the original use case that
> > prompted this bug report will also be checked, as I understand it is
> > more complicated.  Can you ask the relevant people to try that?
> 
> I now also reproduced the original scenario (flycheck with checkers).
> It hangs when building with the last check-in in branch emacs-25
> before your fix and no longer hangs with the current version. Also
> various other people where happy to found the issue fixed in the
> thread over at https://github.com/flycheck/flycheck/issues/794

Thanks, that's good enough for me.  So I'm marking this bug done.

Subject: 25.0.50 (and 24.5.1, 24.4); Sending 4097 bytes to a subprocess hangs Emacs on Windows 8 and 10
From: Clément Pit--Claudel <[email-masked]>
To: [email-masked]
Date: Mon, 11 Jan 2016 00:42:01 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi all,

On Windows, sending more that 4096 bytes at once to a subprocess will cause Emacs to hang (freeze) indefinitely. Killing the subprocess by external means restores functionality. This happens in Emacs 25, 24.5.1, and 24.4 on Windows 8 and 10; I did not try in earlier versions.

Here is how to reproduce the issue:

1. Create a loop.cmd file in C:\. Put the following in it:

:loop
goto loop

2. Run the following snippet in emacs -Q:

(process-send-string
 (start-process "bug" nil "c:/loop.cmd")
 (make-string 4097 ?a))

3. Emacs hangs. Kill cmd.exe from the task manager to make it responsive again. At this point Emacs will display the following:

   Debugger entered--Lisp error: (file-error "Writing to process" "Invalid argument" #<process bug>)
     process-send-string(#<process bug> "(...)")
     eval-region(192 277 t #[257 "\300\242b\210\301\207" [(277) (process-send-string (start-process "bug" nil "c:/loop.cmd") (make-string 4097 97))] 2 "\n\n(fn IGNORE)"])  ; Reading at buffer position 277
     elisp--eval-defun()
     eval-defun(nil)
     funcall-interactively(eval-defun nil)
     call-interactively(eval-defun nil nil)
     command-execute(eval-defun)

Note that the following snippet, on the other hand, runs without issues:

(process-send-string
 (start-process "bug" nil "c:/loop.cmd")
 (make-string 4096 ?a))

I have read sections 7.1 and 7.2 of https://www.gnu.org/software/emacs/manual/html_mono/efaq-w32.html , but I do not believe that the bug is covered by these sections. Indeed, sending the same input in smaller batches works fine. That is, sending 4097 bytes in batches of 50 bytes works fine: Emacs does not hang, and the subprocess properly receives the input.

Here is some context: we've had many users of Flycheck (an alternative to Flymake) on Windows complaining that Flycheck caused Emacs to hang; this happened since we transitioned from passing file names to linters to feeding them source code directly on their stdin. It turns out that this happens when the files in question are more than 4096 characters long. The problem was confirmed with jshint, eshint, and phpcs. I do not know if that means that other linters work fine, or if we didn't get reports from other users. Investigating the bug led me to the minified test case above.

As I mentionned before, sending input in smaller batches works fine. In the case of Flycheck, this means changing this:

  (process-send-region (point-min) (point-max))

to this:

  (goto-char (point-mint))
  (while (not (eobp))
    (let ((from (point)))
      (forward-char (min 50 (- (point-max) (point))))
      (process-send-region process from (point))))

fixes the issue entirely.

I do not use Windows often, but I'll be happy to provide more information, if I can help. I did not compile my own Emacs; I used the one provided at https://sourceforge.net/projects/emacsbinw64/ . The original bug report about Flycheck, which did not identify process-send-string or process-send-region as the culprit, is here: https://github.com/flycheck/flycheck/issues/794 . I have included debug output below.

Thanks,
Clément.

In GNU Emacs 25.0.50.1 (x86_64-w64-mingw32)
 of 2015-11-10
Repository revision: 9145e79dc2042fb477959ddda59c3e2ff5fa3914
Windowing system distributor 'Microsoft Corp.', version 6.3.9600
Configured using:
 'configure --prefix=/z/emacs --host=x86_64-w64-mingw32
 --target=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --with-wide-int
 --with-jpeg --with-xpm --with-png --with-tiff --with-rsvg --with-xml2
 --with-gnutls --with-sound=yes --with-file-notification=yes
 --without-dbus --without-imagemagick 'CFLAGS=-O3 -fomit-frame-pointer
 -g0 -pipe' 'LDFLAGS=-static-libgcc -static-libstdc++ -static -s
 -Wl,-s''

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

Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1252

Major mode: Lisp Interaction

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
  blink-cursor-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 gnus-util mail-extr emacsbug message dired format-spec
rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util help-fns mail-prsvr mail-utils help-mode easymenu cl-loaddefs
pcase cl-lib debug time-date mule-util tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel dos-w32 ls-lisp disp-table
w32-win w32-vars term/common-win tool-bar dnd fontset image regexp-opt
fringe tabulated-list newcomment elisp-mode lisp-mode prog-mode register
page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core 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 charscript case-table epa-hook
jka-cmpr-hook help simple abbrev 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 w32notify w32 multi-tty
make-network-process emacs)

Memory information:
((conses 16 84225 4487)
 (symbols 56 19038 0)
 (miscs 48 64 168)
 (strings 32 14204 4737)
 (string-bytes 1 410641)
 (vectors 16 10727)
 (vector-slots 8 405995 4577)
 (floats 8 130 34)
 (intervals 56 274 32)
 (buffers 976 12))