From d37d7733ceb0ef7a55a45c726ecac3a37423aede Mon Sep 17 00:00:00 2001 From: David Yonge-Mallo Date: Wed, 14 Oct 2026 08:19:03 +0200 Subject: [PATCH] fix(job): wait for subprocess cleanup after timeout --- lua/diffview/job.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lua/diffview/job.lua b/lua/diffview/job.lua index 1e3d9fd2..7cf5ce78 100644 --- a/lua/diffview/job.lua +++ b/lua/diffview/job.lua @@ -443,6 +443,21 @@ function Job:sync(timeout) if not ok then if status == -1 then self:kill(-1) + -- Give SIGTERM a bounded window to reap the subprocess before + -- surrendering, so a timed-out job does not leave a child that + -- outlives this Neovim. If the direct child ignores SIGTERM, fall + -- back to SIGKILL. Grandchildren (`sh -c "...sleep..."` and the like) + -- are reparented past us regardless; this cleans up the common case. + if not vim.wait(500, function() + return self:is_done() + end, 10) then + if self.handle and not self.handle:is_closing() then + pcall(self.handle.kill, self.handle, "sigkill") + end + vim.wait(500, function() + return self:is_done() + end, 10) + end return false, "Synchronous job timed out!" elseif status == -2 then return false, "Synchronous job got interrupted!"