From f238788601eb068d6a95cf775ac4e85c407db2cd Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 18 Aug 2026 11:38:52 -0400 Subject: [PATCH] fix(tui): ui may attempt reattach during shutdown #41368 Problem: TSan CI, always at exit: WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed) #1 uv_mutex_lock #2 tui_flush src/nvim/tui/tui.c:1708 #3 ui_client_event_flush #4 parse_msgpack src/nvim/msgpack_rpc/channel.c:259 ... #10 event_teardown src/nvim/main.c:187 #11 os_exit src/nvim/main.c:720 ... #19 tinput_done_event src/nvim/tui/input.c:184 Analysis (guess): `rpc_close_event()` may run during `event_teardown()` and reattach to a restarted server, then `ui_client_attached=true` gets set and redraws resume in an already-stopped TUI. Solution: Check `!exiting` in `rpc_close_event`, like we already do in `channel_proc_exit_cb()`. --- src/nvim/msgpack_rpc/channel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index 3e5214cb51..fbe1b12ca5 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -512,7 +512,7 @@ static void rpc_close_event(void **argv) bool is_ui_client = ui_client_channel_id && channel->id == ui_client_channel_id; if (is_ui_client) { - if (channel->streamtype != kChannelStreamProc) { + if (!exiting && channel->streamtype != kChannelStreamProc) { ui_client_attach_to_restarted_server(false); } if (ui_client_channel_id != channel->id) {