Skip to content

Fix run_shell timeouts on Windows#1

Open
quicktoolbox wants to merge 2 commits into
mainfrom
fix/windows-run-shell-timeouts
Open

Fix run_shell timeouts on Windows#1
quicktoolbox wants to merge 2 commits into
mainfrom
fix/windows-run-shell-timeouts

Conversation

@quicktoolbox

Copy link
Copy Markdown

Summary

  • move Unix process-group handling behind platform-specific helpers
  • add Windows Job Object handling so run_shell timeouts terminate bash child trees
  • keep direct process-kill fallback when job assignment/termination is unavailable

Verification

  • go test ./internal/jinn -run 'TestRunShell|TestTokenEfficiency_RunShell'
  • go test ./cmd/jinn
  • go build -o /tmp/jinn-pr-check.exe ./cmd/jinn
  • GOOS=linux GOARCH=amd64 go build -o /tmp/jinn-pr-check-linux ./cmd/jinn
  • smoke: {"tool":"run_shell","args":{"command":"printf ok","timeout":5}}

quicktoolbox and others added 2 commits May 20, 2026 12:00
The time.AfterFunc timer goroutine (kill) and the deferred main-goroutine
cleanup could touch the same job-object handle concurrently — timer.Stop()
does not join an in-flight callback. cleanup() could CloseHandle while
kill() was mid-TerminateJobObject, and Windows recycles handle values, so
a use-after-close could terminate an unrelated job.

Add a sync.Mutex to processTree: kill() holds it across TerminateJobObject,
cleanup() holds it while closing and zeroing the handle. configureProcessGroup
now returns *processTree so the mutex is never copied (copylocks). Also
document the grandchild-escape window and the KILL_ON_JOB_CLOSE behavior,
and drop dead `_ = err` lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant