Skip to content

fix(daemon): restore pooled connection timeout after short-timeout operations#638

Merged
Wirasm merged 2 commits intomainfrom
fix/restore-pooled-connection-timeout
Mar 23, 2026
Merged

fix(daemon): restore pooled connection timeout after short-timeout operations#638
Wirasm merged 2 commits intomainfrom
fix/restore-pooled-connection-timeout

Conversation

@Wirasm
Copy link
Owner

@Wirasm Wirasm commented Mar 19, 2026

Summary

  • Four functions (ping_daemon, get_session_status, get_session_info, read_scrollback) set a 2s read timeout on pooled IPC connections but never restored the 30s default before returning to the pool — the next caller on the same thread inherited the corrupted timeout
  • Save original timeout before override, restore before pool return; if restore fails, drop the connection instead of poisoning the pool
  • Add IpcConnection::get_read_timeout() getter to support the save/restore pattern

Test plan

  • New unit test test_get_read_timeout_returns_current_value verifies round-trip save/set/restore
  • cargo fmt --check passes
  • cargo clippy --all -- -D warnings passes
  • cargo test --all passes (all 27 test suites)
  • cargo build --all passes

…erations

Four functions (ping_daemon, get_session_status, get_session_info,
read_scrollback) set a 2s read timeout on pooled IPC connections but
never restored the default 30s before returning to the pool. The next
caller on the same thread inherited the corrupted 2s timeout, causing
spurious timeouts on slower operations.

Save the original timeout before overriding, and restore it before
returning the connection to the pool. If the restore fails, the
connection is dropped rather than poisoning the pool.

Add IpcConnection::get_read_timeout() to support the save/restore
pattern.
@Wirasm
Copy link
Owner Author

Wirasm commented Mar 19, 2026

PR Review Summary

Critical Issues (0 found)

None.

Important Issues (1 found)

Agent Issue Location
code-reviewer The save/restore pattern is repeated 8 times across 4 functions. The same crate already has a TimeoutGuard RAII struct (kild-protocol client.rs:75-84) that solves timeout restoration for is_alive(). A similar RAII approach or a with_short_timeout helper would eliminate the boilerplate and guarantee restoration even on panics or early returns. The current approach is correct for a targeted bug fix, but consider a follow-up to DRY this up. crates/kild-core/src/daemon/client.rs (lines 344-348, 394-398, 421-423, 461-465, 475-477, 571-575, 586-588, 599-601)

Suggestions (2 found)

Agent Suggestion Location
code-simplifier The TimeoutGuard RAII pattern from is_unix_alive() could be lifted into a public helper on IpcConnection to make the save/override/restore cycle a one-liner for callers. This would also make the restore unconditional across all match arms (including the Ok(unexpected) arms that currently just drop the connection). crates/kild-protocol/src/client.rs:75-84
type-design-analyzer get_read_timeout() is well-designed -- mirrors set_read_timeout() symmetrically, handles both stream variants, and matches the stdlib return type exactly. No changes needed. crates/kild-protocol/src/client.rs:244-251

Strengths

  • Correctly identifies a real pool-poisoning bug: short timeouts leaking into pooled connections
  • The "drop instead of return" fallback when restore fails is exactly right -- fail-safe, never poisons the pool
  • New test test_get_read_timeout_returns_current_value verifies the full save/set/restore round-trip
  • Consistent application of the fix across all 4 affected functions
  • PR description clearly explains the root cause and fix strategy

Verdict

READY TO MERGE -- The fix is correct, consistent, and well-tested. The DRY concern is real but appropriate as a follow-up, not a merge blocker for a targeted bug fix.

Recommended Actions

  1. Consider a follow-up PR to extract the save/restore pattern into an RAII helper (reusing the existing TimeoutGuard concept), reducing the 8 repetitions to 4 one-liners
  2. No blocking changes needed

…erations

Replace 8 manual save/set/restore cycles across 4 functions with
IpcConnection::with_read_timeout() — a closure-based helper that
saves the original timeout, sets a short one, runs the caller's
closure, and restores the original on return.
@Wirasm Wirasm merged commit 7a72967 into main Mar 23, 2026
6 checks passed
@Wirasm Wirasm deleted the fix/restore-pooled-connection-timeout branch March 23, 2026 12:41
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