Skip to content

Commit

Permalink
patch 8.1.0889: MS-Windows: a channel write may hang
Browse files Browse the repository at this point in the history
Problem:    MS-Windows: a channel write may hang.
Solution:   Check for WriteFile() not writing anything. (Yasuhiro Matsumoto,
            closes #3920)
  • Loading branch information
brammool committed Feb 10, 2019
1 parent 31b8160 commit 6524068
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/channel.c
Expand Up @@ -91,9 +91,10 @@ fd_write(sock_T fd, char *buf, size_t len)
size = MAX_NAMED_PIPE_SIZE;
else
size = (DWORD)todo;
// If the pipe overflows while the job does not read the data, WriteFile
// will block forever. This abandons the write.
// If the pipe overflows while the job does not read the data,
// WriteFile() will block forever. This abandons the write.
memset(&ov, 0, sizeof(ov));
nwrite = 0;
if (!WriteFile(h, buf + done, size, &nwrite, &ov))
{
DWORD err = GetLastError();
Expand All @@ -104,6 +105,10 @@ fd_write(sock_T fd, char *buf, size_t len)
return -1;
FlushFileBuffers(h);
}
else if (nwrite == 0)
// WriteFile() returns TRUE but did not write anything. This causes
// a hang, so bail out.
break;
todo -= nwrite;
done += nwrite;
}
Expand Down
14 changes: 14 additions & 0 deletions src/testdir/test_channel.vim
Expand Up @@ -2003,6 +2003,20 @@ func Test_raw_large_data()
endtry
endfunc

func Test_no_hang_windows()
if !has('job') || !has('win32')
return
endif

try
let job = job_start(s:python . " test_channel_pipe.py busy",
\ {'mode': 'raw', 'drop': 'never', 'noblock': 0})
call assert_fails('call ch_sendraw(job, repeat("X", 80000))', 'E631:')
finally
call job_stop(job)
endtry
endfunc

func Test_job_exitval_and_termsig()
if !has('unix')
return
Expand Down
3 changes: 3 additions & 0 deletions src/testdir/test_channel_pipe.py
Expand Up @@ -18,6 +18,9 @@
print(sys.argv[1], end='')
sys.stdout.flush()
sys.exit(0)
elif sys.argv[1].startswith("busy"):
time.sleep(100)
sys.exit(0)
else:
print(sys.argv[1])
sys.stdout.flush()
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -783,6 +783,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
889,
/**/
888,
/**/
Expand Down

0 comments on commit 6524068

Please sign in to comment.