]> git.feebdaed.xyz Git - 0xmirror/vim.git/commitdiff
patch 9.1.2025: conpty terminal process may not start
authorMuraoka Taro <koron.kaoriya@gmail.com>
Sat, 27 Dec 2025 14:36:31 +0000 (14:36 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 27 Dec 2025 14:36:31 +0000 (14:36 +0000)
Problem:  Conpty terminal process may not start.
Solution: Do not close the input handle at EOF when conpty is in use.
          (Muraoka Taro)

It causes the following tests to fail in Windows conpty:

          - Test_terminal_duplicate_eof_arg()
          - Test_terminal_eof_arg()
          - Test_terminal_eof_arg_win32_ctrl_z()

To be precise, the process is launched, but immediately after it is
launched, the input handle to the console is closed with the EOF of the
input, and the console is terminated. When the console is terminated,
the associated process is also terminated.

In the Windows pseudo console, input and output handles are closed after
the process in the console has terminated.  This is not explicitly
stated in Microsoft's documentation.  However, looking at the code for
Windows Terminal, which is presented as a complete example of the pseudo
console, it is implemented exactly this way.

See the sample codes below:

- https://github.com/microsoft/terminal/blob/main/samples/ConPTY/EchoCon/EchoCon/EchoCon.cpp
- https://github.com/microsoft/terminal/blob/main/samples/ConPTY/GUIConsole/GUIConsole.ConPTY/Terminal.cs
- https://github.com/microsoft/terminal/blob/main/samples/ConPTY/MiniTerm/MiniTerm/Terminal.cs

The handle that is not closed at EOF is closed when Vim detects the end
of the job, so there is no risk of them being forgotten and leaking.

`ch_anonymous_pipe`, which was used to determine whether a channel was
for conpty, was set to TRUE only when conpty was being used. The
definition also had the comment `// ConPTY` attached to it.  This name
is not very appropriate, but I felt it would be rude to add a new field
to `channel_T` just for this purpose, so I reused it.

closes: #19025

Signed-off-by: Muraoka Taro <koron.kaoriya@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/channel.c
src/terminal.c
src/version.c

index 0d639f522712cd4da0b044251174fff5b3b4dc3b..1248adb174fab886e4fcc746332425b4483c7ec9 100644 (file)
@@ -1635,7 +1635,14 @@ channel_write_in(channel_T *channel)
        ch_log(channel, "Finished writing all lines to channel");
 
        // Close the pipe/socket, so that the other side gets EOF.
-       ch_close_part(channel, PART_IN);
+#ifdef MSWIN
+       // At this point, the input part of the conpty channel must not be
+       // closed.  If it is closed, the pipe will be destroyed, the console
+       // that was using it will be destroyed, and the process running within
+       // it will be forcibly terminated, so this needs to be prevented.
+       if (!channel->ch_anonymous_pipe)
+#endif
+           ch_close_part(channel, PART_IN);
     }
     else
        ch_log(channel, "Still %ld more lines to write",
index 0e7dc87ddb844790c819d602f52f99f859d64dd2..234807e90472854ae462d2bf78b6f233833272b8 100644 (file)
@@ -7167,6 +7167,8 @@ conpty_term_and_job_init(
     channel->ch_write_text_mode = TRUE;
 
     // Use to explicitly delete anonymous pipe handle.
+    // In addition, it is used to prevent the pipe from being closed when input
+    // from a buffer etc. is finished.
     channel->ch_anonymous_pipe = TRUE;
 
     jo = CreateJobObject(NULL, NULL);
index f09ff17915b1f7f9ae5f54366346830a0583fc90..7f80ccf5b47e6b513a6e75d6ada49086505587b2 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2025,
 /**/
     2024,
 /**/