Repository navigation
Fix -c ending other targets early and losing the final IPv6 Echo Reply - #173
Merged
Merged
Conversation
Each probe engine cancelled the token shared by every engine and the receivers as soon as its own -c rounds were done. With several targets (or --resolve-all) the first to finish stopped the others mid-run, and the receivers flushed their in-flight probes as timeouts. Even with one target, the receivers had already shut down before the batch settle window began, so a final-round reply slower than the interval was counted as loss. Engines now just return after their rounds. A shared finish_engines helper, used by batch, streaming and TUI modes, waits for every engine, gives the receivers the probe timeout plus a margin for the last round, then cancels. A quit still cancels immediately and skips that wait.
On Linux, ICMPv6 Echo Replies to a datagram (ping) socket reach only the socket that sent the request, so the engine reads them from its send socket. It polled that socket right after sending each round and checked the -c limit before polling again, so the last round's destination replies were never read and the destination always showed one lost probe. When the -c limit is reached, the IPv6 ICMP engine now keeps polling the send socket until no probe an Echo Reply could answer is pending for its target, the probe timeout passes, or the run is cancelled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two probe-accounting bugs held out of #171 because they change shutdown ordering and needed live testing.
1.
-ccompletion cancelled every other targetSymptom. Each probe engine cancelled the token shared by all engines and the receivers as soon as its own
-crounds were done. With several targets (or--resolve-all), the first one to finish stopped the rest mid-run, and the receivers flushed their in-flight probes as timeouts. It also hit single-target runs: the receivers had already shut down before the batch settle window started, so a final-round reply slower than the interval was counted as loss.Fix. Engines now just return after their rounds and never cancel the shared token. A new
finish_engineshelper inmain.rs, used by batch, streaming and TUI modes, waits for every engine, gives the receiverstimeout + 500msfor the last round, then cancels. Batch mode already had that wait; it just ran after the receivers were gone. Ctrl-C and quit still cancel at once, and batch modes no longer sit through the 3.5 s settle window after a Ctrl-C. An engine error no longer ends the run early:finish_enginesreports it once the other engines are done.2. Final-round IPv6 Echo Replies were never drained
Symptom. On Linux, when ttl falls back to ICMPv6 datagram (ping) sockets because IPv6 raw sockets are unavailable, the destination's Echo Replies reach only the engine's send socket. The engine read that socket right after sending each round and checked the
-climit before reading it again, so the last round's destination reply was never read. The destination always showed one lost probe.Fix. Once the
-climit is reached, the IPv6 ICMP engine keeps reading the send socket (every 10 ms) until no probe at or past the destination TTL is pending for its target, the probe timeout passes, or the run is cancelled.Scope note. With raw sockets, the normal Linux mode since
check_permissionsrequires them, the receive socket also gets the Echo Replies, so the receiver records them with correct RTTs. Live runs on kernel 7.0 show no final-round loss there, before or after this change. The "only the send socket" comment onpoll_ipv6_echo_replyholds for the datagram fallback only. In that fallback the engine also measures destination RTT as roughly one interval, because it reads replies only once per round. That is pre-existing and not changed here.Tests
trace::engine::tests::count_completion_leaves_the_shared_token_aloneruns a real engine (IPv6 UDP to::1, which needs no raw socket) with-c 2and asserts it sends 4 probes and leaves the shared token uncancelled. Fails on master (assertion failed: !cancel.is_cancelled()), checked by putting theself.cancel.cancel()calls back.tests::finish_engines_waits_for_every_engine_then_the_reply_window(paused clock): the run ends 13.5 s in (slowest engine at 10 s plus the 3.5 s window), and a quit returns at once.trace::engine::tests::final_round_ipv6_echo_reply_is_drained(Linux): queues a pending probe, runs the per-round poll before the reply exists, delivers an Echo Reply 50 ms later on a loopback UDP socket standing in for the send socket, and asserts the end-of-run drain records it. Fails with master's behavior (no read after the last round), checked by stubbing the drain to return immediately:assertion failed: pending.read().is_empty().cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo clippy --all-targets --no-default-features -- -D warnings, andcargo testall pass.Live verification
All runs used release builds of master (
47638fd) and this branch inubuntu:24.04containers (NET_RAW).Bug 1, multi-target batch (
-c 10 --json --rate 10 1.1.1.1 8.8.8.8 9.9.9.9 192.0.2.1;--ratemakes the unreachable 30-hop target's rounds longer than the interval):Without
--rate, all targets tick in lockstep and master happens to give every target 10 rounds. Hop 1 (home router) answers 2 to 8 of 10 in both builds because of ICMP rate limiting, so it is not counted as evidence here.Bug 1,
--resolve-all(-c 5 --json --rate 10 --resolve-all one.one.one.one): master gave 1.1.1.1 4 rounds (6 probes neither answered nor timed out) and 1.0.0.1 3 rounds. The branch gives all four addresses (two v4, two v6) 5 rounds, with sent = received + timeouts everywhere.Bug 1,
--stream-json(-c 5 --rate 10 1.1.1.1 192.0.2.1): master's summary shows 192.0.2.1total_sent90 (3 rounds). The branch shows 150 (5 rounds).Bug 1, single target, slow reply (Docker bridge target with
tc netem delay 1500ms,-c 5 --json): master gives the destination 4/5 with 1 timeout, and the branch gives 5/5.Bug 2 (ICMPv6 datagram fallback: Docker IPv6 bridge network, a seccomp profile denying
socket(AF_INET6, SOCK_RAW),net.ipv4.ping_group_range=0 2147483647, target container withnetem delay 30ms,-c 5 --json; two runs each):Raw-socket control on the same network: master gives 5/5 with a 30 ms RTT. On the public internet,
-c 5 --json 2606:4700:4700::1111gives 5/5 at the destination for both builds, and the shutdown trace shows identical timing: engines done at 5.01 s, cancel at 8.51 s.Shutdown
--report -c 30with Ctrl-C at 4 s: master exits after 9.6 s, the branch after 5.0 s. Both print the report.qmid-run: exits in 0.19 s.-c 3 --rate 10 1.1.1.1 192.0.2.1closes by itself after 12.8 s on the branch (the slow target's three rounds plus the reply window). Master closes at 9.3 s, cutting the slow target short.Not covered
o) are still outsidefinish_engines. With-c, the initial targets finishing ends the run, as before. Add-target cancellation was deferred to its own review in Review batch: CLI validation, replay read-only, export safety, docs and CI #171.cfg(target_os = "linux"), and the engine test is behindcfg(unix). CI covers all three.