Skip to content

Commit 9d71fda

Browse files
koronchrisbra
authored andcommitted
patch 9.1.2033: tests: Test_terminal_cwd flaky when using ConPTY
Problem: tests: Test_terminal_cwd in test_terminal.vim fails flaky in the Windows ConPTY terminal. Solution: In ConPTY, the timeout is extended to 1msec when reading a channel associated with a job that is about to finish. This allows Vim to read the last output of a process in a pseudo console. Add comments to make the reasoning clear. (Muraoka Taro) Processes that terminate too quickly in the ConPTY terminal cause Vim to miss their final output. In my environment, the probability of the "cmd /D /c cd" used in Test_terminal_cwd occurring is about 1/4. For a simple statically linked Hello World, the probability of it occurring is about 3/4. closes: #19036 Signed-off-by: Muraoka Taro <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 83fc7c4 commit 9d71fda

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/channel.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4175,7 +4175,17 @@ channel_handle_events(int only_keep_open)
41754175
if (fd == INVALID_FD)
41764176
continue;
41774177

4178-
int r = channel_wait(channel, fd, 0);
4178+
// In normal cases, a timeout of 0 is sufficient.
4179+
//
4180+
// But, in Windows conpty terminals, the final output of a
4181+
// terminated process may be missed. In this case, in order for
4182+
// Vim to read the final output, it is necessary to set the timeout
4183+
// to 1 msec or more. It seems that the final output can be
4184+
// received by calling Sleep() once within channel_wait(). Note
4185+
// that ch_killing can only be TRUE in conpty terminals, so it has
4186+
// no side effects in environments other than conpty.
4187+
int r = channel_wait(channel, fd, (channel->ch_killing &&
4188+
(part == PART_OUT || part == PART_ERR)) ? 1 : 0);
41794189

41804190
if (r == CW_READY)
41814191
channel_read(channel, part, "channel_handle_events");

src/structs.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,8 +2716,14 @@ struct channel_S {
27162716
// reference, the job refers to the channel.
27172717
int ch_job_killed; // TRUE when there was a job and it was killed
27182718
// or we know it died.
2719-
int ch_anonymous_pipe; // ConPTY
2720-
int ch_killing; // TerminateJobObject() was called
2719+
int ch_anonymous_pipe; // Indicates that anonymous pipes are being
2720+
// used for communication in the Windows
2721+
// ConPTY terminal.
2722+
int ch_killing; // Indicates that the job associated with
2723+
// the channel is terminating. It becomes
2724+
// TRUE when TerminateJobObject() was
2725+
// called or the process associated with
2726+
// the job had exited (only ConPTY).
27212727

27222728
int ch_refcount; // reference count
27232729
int ch_copyID;

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+
2033,
737739
/**/
738740
2032,
739741
/**/

0 commit comments

Comments
 (0)