1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 17:55:08 +00:00

fix(timeout): inherit helper state and pass checks

This commit is contained in:
Tw93
2026-03-14 08:32:11 +08:00
parent 0d2f217f28
commit 169be1e1f2
3 changed files with 21 additions and 15 deletions

View File

@@ -55,6 +55,11 @@ if [[ -z "${MO_TIMEOUT_INITIALIZED:-}" ]]; then
echo "[TIMEOUT] Install coreutils for better reliability: brew install coreutils" >&2
fi
# Export so child processes inherit detected values and skip re-detection.
# Without this, children that inherit MO_TIMEOUT_INITIALIZED=1 skip the init
# block but have empty bin vars, forcing the slow shell fallback.
export MO_TIMEOUT_BIN
export MO_TIMEOUT_PERL_BIN
export MO_TIMEOUT_INITIALIZED=1
fi
@@ -181,7 +186,10 @@ run_with_timeout() {
"$@" &
local cmd_pid=$!
# Start timeout killer in background
# Start timeout killer in background.
# Redirect all FDs to /dev/null so orphaned child processes (e.g. sleep $duration)
# do not inherit open file descriptors from the caller and block output pipes
# (notably bats output capture pipes that wait for all writers to close).
(
# Wait for timeout duration
sleep "$duration"
@@ -200,7 +208,7 @@ run_with_timeout() {
kill -KILL -"$cmd_pid" 2> /dev/null || kill -KILL "$cmd_pid" 2> /dev/null || true
fi
fi
) &
) < /dev/null > /dev/null 2>&1 &
local killer_pid=$!
# Wait for command to complete