Skip to content

Commit 9f5b09e

Browse files
koronchrisbra
authored andcommitted
patch 9.1.2025: conpty terminal process may not start
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>
1 parent 4d5b303 commit 9f5b09e

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/channel.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,14 @@ channel_write_in(channel_T *channel)
16351635
ch_log(channel, "Finished writing all lines to channel");
16361636

16371637
// Close the pipe/socket, so that the other side gets EOF.
1638-
ch_close_part(channel, PART_IN);
1638+
#ifdef MSWIN
1639+
// At this point, the input part of the conpty channel must not be
1640+
// closed. If it is closed, the pipe will be destroyed, the console
1641+
// that was using it will be destroyed, and the process running within
1642+
// it will be forcibly terminated, so this needs to be prevented.
1643+
if (!channel->ch_anonymous_pipe)
1644+
#endif
1645+
ch_close_part(channel, PART_IN);
16391646
}
16401647
else
16411648
ch_log(channel, "Still %ld more lines to write",

src/terminal.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7167,6 +7167,8 @@ conpty_term_and_job_init(
71677167
channel->ch_write_text_mode = TRUE;
71687168

71697169
// Use to explicitly delete anonymous pipe handle.
7170+
// In addition, it is used to prevent the pipe from being closed when input
7171+
// from a buffer etc. is finished.
71707172
channel->ch_anonymous_pipe = TRUE;
71717173

71727174
jo = CreateJobObject(NULL, NULL);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
2025,
737739
/**/
738740
2024,
739741
/**/

0 commit comments

Comments
 (0)