From 924a8e42389194e9fc270c0fdf7fab2490efce71 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 13 Sep 2025 20:53:17 +0800 Subject: [PATCH] fix(tui): don't wait for DA1 response when stdin is closed (#35745) (cherry picked from commit 4a69847df45dc1dc8f7ee546a62ea6f5ef0825f9) --- src/nvim/tui/tui.c | 9 +++++++-- test/functional/terminal/tui_spec.lua | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 52e4fd7bca..6a6de4c15d 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -646,8 +646,13 @@ void tui_stop(TUIData *tui) tui->input.callbacks.primary_device_attr = tui_stop_cb; terminfo_disable(tui); - // Wait until DA1 response is received - LOOP_PROCESS_EVENTS_UNTIL(tui->loop, tui->loop->events, EXIT_TIMEOUT_MS, tui->stopped); + // Wait until DA1 response is received, or stdin is closed (#35744). + LOOP_PROCESS_EVENTS_UNTIL(tui->loop, tui->loop->events, EXIT_TIMEOUT_MS, + tui->stopped || tui->input.read_stream.did_eof); + if (!tui->stopped && !tui->input.read_stream.did_eof) { + WLOG("TUI: timed out waiting for DA1 response"); + } + tui->stopped = true; tui_terminal_stop(tui); stream_set_blocking(tui->input.in_fd, true); // normalize stream (#2598) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 3f72442e73..5215983755 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -2159,6 +2159,16 @@ describe('TUI', function() screen:expect({ any = vim.pesc('[Process exited 1]') }) end) + it('exits immediately when stdin is closed #35744', function() + local chan = api.nvim_get_option_value('channel', { buf = 0 }) + local pid = fn.jobpid(chan) + fn.chanclose(chan) + retry(nil, 50, function() + eq(vim.NIL, api.nvim_get_proc(pid)) + end) + screen:expect({ any = vim.pesc('[Process exited 1]') }) + end) + it('no stack-use-after-scope with cursor color #22432', function() screen:set_option('rgb', true) command('set termguicolors')