Subject: bug#43226: 28.0.50; Running Tramp tests on MS-Windows leaves zombie processes on the remote

From: HA <[email-masked]>
Date: Wed, 26 Oct 2022 17:15:34 +0300

Eli Zaretskii <[email-masked]> writes:

> So the ->pty_flag case is not for Windows.  And even if we did try
> using it, it wouldn't have worked for local processes, because Ctrl-D
> is NOT the EOF character on Windows; it's Ctrl-Z, and then only if the
> sub-process does text-mode reads (in binary mode, there's no way to
> send EOF to a subprocess, only kill it).

You're right – when trying the test case with just ssh in Emacs 28 on
Windows, process-send-eof successfully terminates the remote cat
process, it just never receives the actual Ctrl-D. (Verified this by
stracing the remote cat process.)

The test case where I call start-file-process with default-directory
pointing to a remote directory ("/sshx:...") and run simply "cat"
behaves differently in that it runs cmdproxy.exe instead of ssh.exe
directly, uses the -t option twice to force creation of PTYs on the
remote end, and uses -o RemoteCommand="/bin/sh -i" for interactive
shell. It does not seem to receive any input from Emacs, and stays
running.

Same things also happens if I run the test with "ssh -t -t" so
apparently somehow pseudo terminals on the remote end causes issues
here.

The normal "ssh" method (without -x) does not seem to be able to connect
at all on my Windows system for whatever reason, so I can't comment if
works any better.

Interestingly, similar test on Emacs 27.1 on GNU/Linux
receives the input but the cat process also stays running there, so
not sure if process-send-eof does the right thing even here.

(let* ((default-directory "/sshx:happy:/tmp")
      (sshz (start-file-process "eoftest" (get-buffer-create "*eoftest*") "cat")))
  (list-processes)
  (sit-for 10) ; Run strace -p $(pgrep cat) on remote
  (process-send-string sshz "foo")
  (process-send-eof sshz))

strace: Process 18005 attached
read(0, "foo", 131072)                  = 3
write(1, "foo", 3)                      = 3
read(0,