wait_for_bead: kill 9p read child on exit to prevent hang in execute_code

cmd.Run() waits for stdout pipe EOF, but the 9p read subprocess
spawned by process substitution inherits the fd and keeps it open
after bash exits. Capture the PID and kill it in an EXIT trap.
This commit is contained in:
Levi Neely 2026-03-15 07:33:29 +01:00
parent 1df382c441
commit 32a3016f0d
1 changed files with 6 additions and 2 deletions

View File

@ -20,7 +20,11 @@ fi
EXPECTED_SOURCE="beads/$MOUNT"
while IFS= read -r line; do
exec 3< <(9p read anvillm/events 2>/dev/null)
EVENTS_PID=$!
trap 'kill $EVENTS_PID 2>/dev/null; exec 3<&-' EXIT
while IFS= read -r line <&3; do
type=$(echo "$line" | jq -r '.type // empty' 2>/dev/null)
[ "$type" = "BeadReady" ] || continue
@ -30,4 +34,4 @@ while IFS= read -r line; do
# Emit full bead data and exit — bot decides whether to claim
echo "$line" | jq '.data'
exit 0
done < <(9p read anvillm/events 2>/dev/null)
done