fix: clean goroutine exit in timeout message helpers
Add done channel to runGitCmdWithTimeoutMsg and runCmdWithTimeoutMessage so goroutines exit immediately when command completes, rather than waiting for the full timeout duration. Follow-up to PR #678. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -785,17 +785,21 @@ func fetchAndRebaseInWorktree(ctx context.Context, worktreePath, branch, remote
|
||||
//
|
||||
// Returns: combined output and error from the command
|
||||
func runCmdWithTimeoutMessage(ctx context.Context, timeoutMsg string, timeoutDelay time.Duration, cmd *exec.Cmd) ([]byte, error) {
|
||||
// Start a timer to print a message if the command takes too long
|
||||
// Use done channel to cleanly exit goroutine when command completes
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
select {
|
||||
case <-time.After(timeoutDelay):
|
||||
fmt.Fprintf(os.Stderr, "⏳ %s\n", timeoutMsg)
|
||||
case <-done:
|
||||
// Command completed, exit cleanly
|
||||
case <-ctx.Done():
|
||||
// Context canceled, don't print message
|
||||
}
|
||||
}()
|
||||
|
||||
output, err := cmd.CombinedOutput()
|
||||
close(done)
|
||||
return output, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user