fix: non-blocking ShellExecutor — deadlock-safe, with tests#11
Merged
Conversation
…implementation Three bugs fixed: 1. `waitUntilExit()` blocked Swift's cooperative thread pool — replaced with `withCheckedThrowingContinuation` + `terminationHandler` so no thread is held while waiting for the subprocess. 2. Timeout error was silently swallowed — the throw inside the old timeout `Task` never escaped to the caller. Now both the termination handler and the timeout race via `OSAllocatedUnfairLock<Bool>`; first one wins and resumes the continuation correctly. 3. Pipe buffer deadlock — `readDataToEndOfFile()` after `waitUntilExit()` deadlocks if output exceeds ~64 KB. Fixed with `readabilityHandler` draining into `OSAllocatedUnfairLock<Data>` buffers as data arrives. Also converts `actor ShellExecutor` to `final class` so concurrent `execute()` calls across multiple users can run in true parallel rather than serializing through the actor. Co-Authored-By: Buqian Zheng <zhengbuqian@gmail.com>
…tterns, add ShellExecutor tests - Cancel the timeout Task via OSAllocatedUnfairLock<Task?> when terminationHandler fires so it doesn't linger for the full timeout duration after fast commands - Extract networkErrorPatterns to a static constant; was duplicated between execute() and checkGHAuthenticated(), with "failed to connect" missing from the latter - Make parseHosts internal (was private) so @testable import can reach it - Add ShellExecutorTests: 6 parseHosts unit tests + 1 timeout integration test - Fix pre-existing Swift 6 build errors in PRMonitorViewModelTests: add @mainactor to ParsePRURLTests, OtherPRsServiceTests, PRTypeDisplayTitleTests, and CustomNamesServiceTests (all test @MainActor-inferred types) Co-Authored-By: Buqian Zheng <zhengbuqian@users.noreply.github.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports the
ShellExecutorrewrite from PR #8 (credit: @zhengbuqian) with additional fixes and test coverage identified during review.What the original rewrite fixed (from #8):
waitUntilExit()blocked Swift's cooperative thread pool → replaced withterminationHandler+withCheckedThrowingContinuationreadabilityHandlerstreams data incrementally viaOSAllocatedUnfairLock<Data>actor ShellExecutorserialized concurrent task-group calls → converted tofinal classfor true parallelismAdditional fixes in this PR:
Taskwas never cancelled after normal process exit — leaked for the full timeout duration (30s by default). Fixed viaOSAllocatedUnfairLock<Task<Void, Never>?>soterminationHandlercancels it immediately.networkErrorPatternswas duplicated betweenexecute()andcheckGHAuthenticated(), and"failed to connect"was missing from the latter copy. Extracted to a singlestatic let.PRMonitorViewModelTests: four test structs were calling@MainActor-inferred types from non-isolated contexts. Added@MainActortoParsePRURLTests,OtherPRsServiceTests,PRTypeDisplayTitleTests, andCustomNamesServiceTests.Test plan
ShellExecutorTestssuite: 6parseHostsunit tests + 1 timeout integration test (sleep 10with 0.1s timeout assertsexecutionFailed("…timed out…"))Attribution
Core
ShellExecutorrewrite originally authored by @zhengbuqian in #8.🤖 Generated with Claude Code