Skip to content

fix: critical state machine and process timeout bugs - #26

Merged
zoosky merged 3 commits into
mainfrom
fix/critical-audit-fixes
Apr 5, 2026
Merged

fix: critical state machine and process timeout bugs#26
zoosky merged 3 commits into
mainfrom
fix/critical-audit-fixes

Conversation

@zoosky

@zoosky zoosky commented Apr 5, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes three critical bugs from Feature 017 (Code Audit):

  • State machine counter bug — Aggregate failure counters incremented N times per round (once per target) instead of once. With 3 targets and degraded_threshold=3, a single round of failures jumped straight to OFFLINE. Now tracks round completion and evaluates state only after all targets report.
  • Traceroute process timeouttraceroute subprocess had no hard timeout; could hang indefinitely on broken networks (exactly when it's invoked). Added tokio::select! with configurable process_timeout_ms.
  • Gateway ping process timeoutping_host() had no process timeout and used hardcoded 2000ms. Now uses config values and the same kill-on-timeout pattern as ping.rs.

Test plan

  • All 62 tests pass (60 existing + 2 new multi-target round tests)
  • Zero clippy warnings
  • test_multi_target_round_counting — verifies fix: 2-target rounds don't skip states
  • test_process_round_batch — verifies new process_round() batch API
  • Manual: cargo run -- --dev start -f with default 2 targets, verify DEGRADED/OFFLINE transitions take expected number of rounds

zoosky added 3 commits April 5, 2026 20:53
Fix three critical bugs identified in the code audit:

1. State machine counter bug: aggregate failure/success counters were
   incremented once per target per round instead of once per round.
   With N targets, this caused premature state transitions (e.g.,
   ONLINE->OFFLINE in a single round with 3 targets). Now tracks
   round completion and only evaluates state after all targets report.

2. Traceroute process timeout: traceroute subprocess had no hard
   timeout and could hang indefinitely on broken networks. Added
   tokio::select! with configurable process_timeout_ms, matching
   the pattern already used in ping.rs.

3. Gateway ping process timeout: ping_host() had no process timeout
   and used hardcoded 2000ms instead of config values. Now uses
   configured ping_timeout_ms and process_timeout_ms.
@zoosky
zoosky merged commit 8dca38a into main Apr 5, 2026
4 checks passed
@zoosky
zoosky deleted the fix/critical-audit-fixes branch April 5, 2026 19:43
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