mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
fixup2: process.c: Prevent data loss for process output streams
The only data loss should be, if a process forked a child that keeps sending data after the parent terminated. While not in teardown mode we could keep reading child data, but then `:!cmd` would block after `cmd` exited. In teardown mode we want to exit nvim so we cannot keep reading child data.
This commit is contained in:
@@ -364,8 +364,10 @@ static void flush_stream(Process *proc, Stream *stream)
|
|||||||
size_t num_bytes = stream->num_bytes;
|
size_t num_bytes = stream->num_bytes;
|
||||||
|
|
||||||
// Poll for data and process the generated events.
|
// Poll for data and process the generated events.
|
||||||
loop_poll_events(&loop, 0);
|
loop_poll_events(proc->loop, 0);
|
||||||
queue_process_events(proc->events);
|
if (proc->events) {
|
||||||
|
queue_process_events(proc->events);
|
||||||
|
}
|
||||||
|
|
||||||
// Stream can be closed if it is empty.
|
// Stream can be closed if it is empty.
|
||||||
if (num_bytes == stream->num_bytes) {
|
if (num_bytes == stream->num_bytes) {
|
||||||
@@ -400,11 +402,12 @@ static void on_process_exit(Process *proc)
|
|||||||
uv_timer_stop(&loop->children_kill_timer);
|
uv_timer_stop(&loop->children_kill_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process handles are closed in the next event loop tick. This is done to
|
// Process has terminated, but there could still be data to be read from the
|
||||||
// give libuv more time to read data from the OS after the process exits(If
|
// OS. We are still in the libuv loop, so we cannot call code that polls for
|
||||||
// process_close_streams is called with data still in the OS buffer, we lose
|
// more data directly. Instead delay the reading after the libuv loop by
|
||||||
// it)
|
// queueing process_close_handles() as an event.
|
||||||
CREATE_EVENT(proc->events, process_close_handles, 1, proc);
|
Queue *queue = proc->events ? proc->events : loop->events;
|
||||||
|
CREATE_EVENT(queue, process_close_handles, 1, proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_process_stream_close(Stream *stream, void *data)
|
static void on_process_stream_close(Stream *stream, void *data)
|
||||||
|
|||||||
Reference in New Issue
Block a user