From ff386f442d725017f1760d88d4362bca43d1718d Mon Sep 17 00:00:00 2001 From: Maor Hamami Date: Tue, 17 Mar 2026 11:58:42 +0200 Subject: [PATCH 1/2] [windows] try to fix hanging processes --- btest-bg-run-helper | 17 ++++++++++++++--- btest-bg-wait | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/btest-bg-run-helper b/btest-bg-run-helper index 61688dc..db5689f 100755 --- a/btest-bg-run-helper +++ b/btest-bg-run-helper @@ -11,9 +11,15 @@ esac # taskkill /T terminates the process and all its descendants. # MSYS_NO_PATHCONV prevents MSYS from interpreting /F, /T, /PID as paths. win_kill_tree() { - local wpid - if [ $is_windows -eq 1 ] && [ -f .winpid ]; then - wpid=$(cat .winpid) + if [ $is_windows -eq 1 ]; then + local wpid="" + # Prefer the live /proc lookup: after exec the Windows PID may + # differ from the value captured at startup in .winpid. + if [ -n "$pid" ] && [ -f /proc/"$pid"/winpid ]; then + wpid=$(cat /proc/"$pid"/winpid) + elif [ -f .winpid ]; then + wpid=$(cat .winpid) + fi if [ -n "$wpid" ]; then MSYS_NO_PATHCONV=1 taskkill /F /T /PID "$wpid" &>/dev/null fi @@ -67,6 +73,11 @@ if [ $is_windows -eq 1 ] && [ -f /proc/$pid/winpid ]; then cat /proc/$pid/winpid >.winpid fi +# Also record the child's MSYS PID. btest-bg-wait can use this to +# look up the *current* Windows PID via /proc at kill time, which is +# more reliable than .winpid because exec may change the Windows PID. +echo $pid >.child_pid + wait $pid rc=$? diff --git a/btest-bg-wait b/btest-bg-wait index d1a65c4..c5359b9 100755 --- a/btest-bg-wait +++ b/btest-bg-wait @@ -81,6 +81,23 @@ function kill_procs { MSYS_NO_PATHCONV=1 taskkill /F /T /PID "$wpid" &>/dev/null fi fi + + # The .winpid captured at startup may hold a stale + # pre-exec Windows PID. Look up the *current* Windows + # PID from /proc using the child's MSYS PID, which + # remains valid and tracks the native process after exec. + if [ -f "$p/.child_pid" ]; then + local cpid + cpid=$(cat "$p/.child_pid") + if [ -n "$cpid" ] && [ -f /proc/"$cpid"/winpid ]; then + local live_wpid + live_wpid=$(cat /proc/"$cpid"/winpid) + if [ -n "$live_wpid" ]; then + MSYS_NO_PATHCONV=1 taskkill /F /T /PID "$live_wpid" &>/dev/null + fi + fi + fi + if [ -f "$p/.pid" ]; then msys_pids="$msys_pids $(cat "$p/.pid")" fi From 9b8903689d410388abc7b35c60f99922109dadc8 Mon Sep 17 00:00:00 2001 From: Maor Hamami Date: Wed, 18 Mar 2026 11:48:01 +0200 Subject: [PATCH 2/2] code review changes --- btest-bg-run-helper | 11 ++++++----- btest-bg-wait | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/btest-bg-run-helper b/btest-bg-run-helper index db5689f..fbd8d04 100755 --- a/btest-bg-run-helper +++ b/btest-bg-run-helper @@ -69,15 +69,16 @@ echo $$ >.pid # Record the child's Windows PID so that btest-bg-wait can # reliably terminate it even if MSYS PIDs become stale. +# Also record the child's MSYS PID (.winchildpid): btest-bg-wait +# can use it to look up the *current* Windows PID via /proc at kill +# time, which is more reliable than .winpid because exec may change +# the Windows PID. +# Guard: /proc entry disappears if the child exits before we get here. if [ $is_windows -eq 1 ] && [ -f /proc/$pid/winpid ]; then cat /proc/$pid/winpid >.winpid + echo $pid >.winchildpid fi -# Also record the child's MSYS PID. btest-bg-wait can use this to -# look up the *current* Windows PID via /proc at kill time, which is -# more reliable than .winpid because exec may change the Windows PID. -echo $pid >.child_pid - wait $pid rc=$? diff --git a/btest-bg-wait b/btest-bg-wait index c5359b9..39ed04f 100755 --- a/btest-bg-wait +++ b/btest-bg-wait @@ -86,9 +86,9 @@ function kill_procs { # pre-exec Windows PID. Look up the *current* Windows # PID from /proc using the child's MSYS PID, which # remains valid and tracks the native process after exec. - if [ -f "$p/.child_pid" ]; then + if [ -f "$p/.winchildpid" ]; then local cpid - cpid=$(cat "$p/.child_pid") + cpid=$(cat "$p/.winchildpid") if [ -n "$cpid" ] && [ -f /proc/"$cpid"/winpid ]; then local live_wpid live_wpid=$(cat /proc/"$cpid"/winpid)