Skip to content

Commit d8b5549

Browse files
committed
patch 7.4.2297
Problem: When starting a job that reads from a buffer and reaching the end, the job hangs. Solution: Close the pipe or socket when all lines were read.
1 parent f37506f commit d8b5549

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/channel.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,11 +1424,14 @@ channel_write_in(channel_T *channel)
14241424
ch_logn(channel, "written %d lines to channel", written);
14251425

14261426
in_part->ch_buf_top = lnum;
1427-
if (lnum > buf->b_ml.ml_line_count)
1427+
if (lnum > buf->b_ml.ml_line_count || lnum > in_part->ch_buf_bot)
14281428
{
14291429
/* Writing is done, no longer need the buffer. */
14301430
in_part->ch_bufref.br_buf = NULL;
14311431
ch_log(channel, "Finished writing all lines to channel");
1432+
1433+
/* Close the pipe/socket, so that the other side gets EOF. */
1434+
may_close_part(&channel->CH_IN_FD);
14321435
}
14331436
else
14341437
ch_logn(channel, "Still %d more lines to write",

src/testdir/test_channel.vim

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,46 @@ func Test_pipe_from_buffer_nr()
792792
call Run_test_pipe_from_buffer(0)
793793
endfunc
794794

795+
func Run_pipe_through_sort(all)
796+
if !executable('sort') || !has('job')
797+
return
798+
endif
799+
split sortin
800+
call setline(1, ['ccc', 'aaa', 'ddd', 'bbb', 'eee'])
801+
let options = {'in_io': 'buffer', 'in_name': 'sortin',
802+
\ 'out_io': 'buffer', 'out_name': 'sortout'}
803+
if !a:all
804+
let options.in_top = 2
805+
let options.in_bot = 4
806+
endif
807+
let g:job = job_start('sort', options)
808+
call assert_equal("run", job_status(g:job))
809+
call WaitFor('job_status(g:job) == "dead"')
810+
call assert_equal("dead", job_status(g:job))
811+
sp sortout
812+
call assert_equal('Reading from channel output...', getline(1))
813+
if a:all
814+
call assert_equal(['aaa', 'bbb', 'ccc', 'ddd', 'eee'], getline(2, 6))
815+
else
816+
call assert_equal(['aaa', 'bbb', 'ddd'], getline(2, 4))
817+
endif
818+
819+
call job_stop(g:job)
820+
unlet g:job
821+
bwipe! sortin
822+
bwipe! sortout
823+
endfunc
824+
825+
func Test_pipe_through_sort_all()
826+
call ch_log('Test_pipe_through_sort_all()')
827+
call Run_pipe_through_sort(1)
828+
endfunc
829+
830+
func Test_pipe_through_sort_some()
831+
call ch_log('Test_pipe_through_sort_some()')
832+
call Run_pipe_through_sort(0)
833+
endfunc
834+
795835
func Test_pipe_to_nameless_buffer()
796836
if !has('job')
797837
return

src/version.c

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

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2297,
766768
/**/
767769
2296,
768770
/**/

0 commit comments

Comments
 (0)