Skip to content

Fix agent shutdown hanging on Ctrl+C#39

Merged
gricha merged 2 commits intomainfrom
fix-agent-shutdown-hang
Jan 7, 2026
Merged

Fix agent shutdown hanging on Ctrl+C#39
gricha merged 2 commits intomainfrom
fix-agent-shutdown-hang

Conversation

@gricha
Copy link
Copy Markdown
Owner

@gricha gricha commented Jan 7, 2026

Summary

  • Fixes the issue where perry agent run hangs on Ctrl+C, requiring double Ctrl+C to exit
  • Adds proper graceful shutdown with a 3-second timeout fallback
  • Cancels background image pull timers on shutdown
  • Force-closes all HTTP keep-alive connections immediately

Changes

src/agent/run.ts:

  • Added isShuttingDown flag - first Ctrl+C triggers graceful shutdown, second Ctrl+C force-exits
  • Call stopEagerImagePull() to cancel background timers
  • Call server.closeAllConnections() to force-close lingering HTTP connections
  • Added 3-second force exit timeout (with .unref() so it doesn't keep the event loop alive)

src/docker/eager-pull.ts:

  • Added AbortController to signal cancellation of pending retries
  • All setTimeout calls now use .unref() so they don't prevent process exit
  • Added stopEagerImagePull() export to abort image pull attempts

Behavior

  1. Single Ctrl+C: Logs "Shutting down...", closes all connections immediately, exits cleanly
  2. If graceful shutdown hangs: Force exits after 3 seconds
  3. Double Ctrl+C: Force exits immediately

@gricha gricha force-pushed the fix-agent-shutdown-hang branch from 2992530 to 68c3239 Compare January 7, 2026 21:30
Comment thread src/agent/run.ts
Comment on lines 314 to 316
if (tailscaleServeActive) {
console.log('[agent] Stopping Tailscale Serve...');
await stopTailscaleServe();

This comment was marked as outdated.

@gricha gricha merged commit f2d6ddb into main Jan 7, 2026
6 checks passed
@gricha gricha deleted the fix-agent-shutdown-hang branch January 7, 2026 22:04
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