Skip to content

fix: TUI async polling, replay validation, assert→Result (LAN-150, LAN-181) - #116

Merged
lance0 merged 3 commits into
masterfrom
fix/lan-150-181-polish
Jul 6, 2026
Merged

lance0 merged 3 commits into
masterfrom
fix/lan-150-181-polish

Conversation

@lance0

@lance0 lance0 commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Closes LAN-150 and LAN-181 — the last two open ttl issues.

LAN-150 #32 — TUI input polling blocks async runtime

Problem: event::poll(tick_rate) and event::read() are blocking calls running on the tokio executor, stalling it for up to 16ms per frame iteration.

Fix: Spawn a dedicated std::thread that runs the crossterm event loop and forwards Event values over an mpsc channel. The async loop uses try_recv() (non-blocking) and tokio::time::sleep(tick_rate) for frame pacing.

Files: src/tui/app.rs — new spawn_event_reader() helper, run_app input handling switched from blocking event::poll/event::read to non-blocking try_recv.

LAN-150 #22 — Replay/diff bypasses CLI validation

Problem: args.validate() ran after the replay/diff early returns in main(), so nonsensical flags (e.g. --pmtud --replay) were accepted silently.

Fix: Move validate() before the early returns. Add validation rules rejecting --pmtud and --jumbo in replay/diff modes.

Files: src/main.rs, src/cli.rs.

LAN-181 — assert! in build_ipv4_packet production path panics

Problem: build_ipv4_packet used assert! to guard against oversized IPv4 packets — a production panic path.

Fix: Convert to Result<Vec<u8>> using anyhow::bail!. All 4 production callers in engine.rs updated: 3 use ? (in Result-returning functions), 1 (PMTUD bool fn) handles Err with eprintln! + return false.

Files: src/probe/rawip.rs, src/trace/engine.rs.

Tests

  • test_build_ipv4_packet_oversized_returns_err — replaces should_panic with is_err + error message check
  • test_pmtud_rejected_with_replay — validates --pmtud + --replay is rejected
  • test_jumbo_rejected_with_replay — validates --jumbo + --replay is rejected
  • test_pmtud_rejected_with_diff — validates --pmtud + --diff is rejected
  • test_validate_passes_for_plain_replay — plain --replay still validates
  • test_validate_passes_for_plain_diff — plain --diff still validates

All 603 tests pass, clippy clean.

lance0 added 3 commits July 6, 2026 12:08
…N-181)

Three fixes in one PR:

LAN-150 #32 — TUI input polling blocks async runtime:
- Spawn a dedicated std::thread for crossterm event::poll/read (blocking
  calls that previously ran on the tokio executor, stalling it for up to
  16ms per frame).
- The thread forwards Event values over an mpsc channel; the async loop
  uses try_recv (non-blocking) and tokio::time::sleep for frame pacing.

LAN-150 #22 — Replay/diff bypasses CLI validation:
- Move args.validate() before the replay/diff early returns in main()
  so nonsensical flag combos are caught in all modes.
- Add validation rules: --pmtud and --jumbo rejected with --replay/--diff.

LAN-181 — assert! in build_ipv4_packet production path:
- Convert build_ipv4_packet to return Result<Vec<u8>> instead of Vec<u8>
  with an assert! that panics on oversized packets.
- All 4 production callers in engine.rs updated: 3 use ? (in Result-
  returning functions), 1 (PMTUD bool fn) handles Err with eprintln +
  return false.
- Tests updated: should_panic → is_err, all test callsites use
  .unwrap()/.expect().
Review finding: moving validate() before replay/diff dispatch broke
--replay/--diff combined with --json/--csv/--report/--no-tui, because
validate() still treated those as live/batch modes requiring targets
and -c.

Fix: gate the target and count checks with !replay_or_diff so replay
and diff modes skip live-probe validations.

Added 5 tests covering the regression: --replay with --json/--csv/
--report/--no-tui, and --diff with --json.
@lance0
lance0 merged commit 5ce8279 into master Jul 6, 2026
5 checks passed
@lance0
lance0 deleted the fix/lan-150-181-polish branch July 6, 2026 16: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