Skip to content

Add timeout and fix resource leaks in Git client#21

Merged
Iron-Ham merged 1 commit intomainfrom
fix/git-timeout-resource-leaks
Jan 7, 2026
Merged

Add timeout and fix resource leaks in Git client#21
Iron-Ham merged 1 commit intomainfrom
fix/git-timeout-resource-leaks

Conversation

@Iron-Ham
Copy link
Owner

@Iron-Ham Iron-Ham commented Jan 7, 2026

Summary

The runGit() function in SystemGitClient had no timeout on pipe reads or process exit, which could cause hangs on large diffs or stalled git processes. Additionally, pipe file handles were never explicitly closed, potentially causing file descriptor exhaustion across multiple runs.

Changes:

  • Add 60s timeout using DispatchGroup with wait(timeout:)
  • Add defer block to always close pipe file handles after reading
  • Add gitCommandTimedOut(command:timeout:) error case for timeout failures
  • Use DataBox wrapper class (@unchecked Sendable) to avoid Swift concurrency warnings
  • Fix unrelated test that was checking for non-existent prompt text

Test plan

  • Build passes with swift build
  • All 49 existing tests pass
  • Manual test: verify large diffs complete within timeout
  • Manual test: verify file descriptors don't leak (check with lsof)

Fixes #17

The runGit() function had no timeout on pipe reads or process exit,
which could cause hangs on large diffs. Pipe file handles were also
never explicitly closed, potentially leaking file descriptors across
multiple runs.

Changes:
- Add 60s timeout using DispatchGroup with wait(timeout:)
- Add defer block to always close pipe file handles
- Add gitCommandTimedOut error case for timeout failures
- Use DataBox wrapper to avoid Swift concurrency warnings
- Fix unrelated test checking for non-existent prompt text

Fixes #17
@Iron-Ham Iron-Ham merged commit d44ad63 into main Jan 7, 2026
1 check passed
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.

Git process operations have no timeout and leak file descriptors

1 participant