Skip to content

perf: use spawn_blocking instead of OS threads for per-connection handling#834

Draft
svarlamov wants to merge 3 commits intomainfrom
fix/stale-daemon-recovery
Draft

perf: use spawn_blocking instead of OS threads for per-connection handling#834
svarlamov wants to merge 3 commits intomainfrom
fix/stale-daemon-recovery

Conversation

@svarlamov
Copy link
Copy Markdown
Member

@svarlamov svarlamov commented Mar 27, 2026

Summary

  • Use spawn_blocking for per-connection handling: Replaces std::thread::spawn with tokio::spawn_blocking in both control and trace listener loops (Unix path). This reuses tokio's bounded blocking thread pool instead of creating unbounded OS threads per git invocation.
  • Bounded shutdown: Adds runtime.shutdown_timeout(5s) after run_daemon returns so in-flight spawn_blocking handlers don't stall process exit indefinitely.

Test plan

  • All 50 daemon integration tests pass
  • cargo clippy clean on all platforms (including Windows unused variable fix)
  • cargo fmt clean

🤖 Generated with Claude Code

svarlamov and others added 2 commits March 27, 2026 17:07
…dling

Replaces std::thread::Builder::new().spawn() with
runtime_handle.spawn_blocking() in both control and trace listener loops.
This reuses tokio's bounded blocking thread pool instead of creating an
unbounded number of OS threads (one per git invocation).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The runtime_handle parameter is only used in the Unix path
(spawn_blocking) but not in the Windows fixed-worker-pool path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

…exit

When the tokio runtime drops, it blocks waiting for all in-flight
spawn_blocking tasks. If a handler is blocked reading from a slow git
process, this could hang the daemon process indefinitely. Cap the wait
at 5 seconds so the process exits cleanly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@svarlamov svarlamov changed the title fix: prevent daemon half-alive state and add hard shutdown/restart perf: use spawn_blocking instead of OS threads for per-connection handling Mar 27, 2026
@svarlamov svarlamov marked this pull request as draft March 28, 2026 00:57
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