Repository navigation
fix: PMTUD correlation, lock ordering, and enrichment dedup - #104
Merged
Merged
Conversation
- Pass is_pmtud_response to remove_pending_by_flow_hint so Frag Needed / Packet Too Big responses prefer the PMTUD pending entry over normal, preventing PMTUD probe from timing out and converging to wrong MTU (#3) - Explicitly scope sessions read guard before acquiring pending write lock in receiver drain loop, documenting the lock order to prevent deadlock (#10) - Deduplicate IPs via HashSet before take(MAX_CONCURRENT) in all four enrichment workers (ASN, rDNS, GeoIP, IX) to avoid redundant lookups (#12) All 493 tests pass; clippy clean.
There was a problem hiding this comment.
Pull request overview
This PR improves traceroute receiver correctness and background enrichment efficiency by (1) preferring PMTUD pending probes when handling PMTUD-related ICMP responses, (2) documenting and attempting to enforce a safer lock acquisition order in the receiver drain loop, and (3) deduplicating enrichment lookup targets so concurrent lookup capacity isn’t wasted on repeat IPs.
Changes:
- Adjust pending-probe correlation to prefer PMTUD entries for Frag Needed / Packet Too Big responses, including an added unit test.
- Refactor the receiver drain loop to drop
sessions.read()before takingpending.write(), and document intended lock ordering. - Deduplicate enrichment worker IP batches before applying the concurrency cap.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/trace/receiver.rs |
Updates probe matching to prefer PMTUD pending entries and adds a PMTUD preference test; adds lock-order documentation and scopes sessions.read() in the drain loop. |
src/lookup/asn.rs |
Deduplicates IPs prior to take(MAX_CONCURRENT_LOOKUPS) for ASN enrichment batch selection. |
src/lookup/rdns.rs |
Deduplicates IPs prior to take(MAX_CONCURRENT_LOOKUPS) for reverse DNS enrichment batch selection. |
src/lookup/geo.rs |
Deduplicates IPs prior to take(MAX_CONCURRENT_LOOKUPS) for GeoIP enrichment batch selection. |
src/lookup/ix.rs |
Deduplicates IPs prior to take(MAX_CONCURRENT_LOOKUPS) for IX enrichment batch selection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+220
to
+226
| // Collect target list BEFORE acquiring the pending lock. | ||
| // Lock order: sessions.read() is always acquired and released | ||
| // before pending.write() to prevent deadlock. | ||
| let fallback_targets: Vec<IpAddr> = { | ||
| let sessions = self.sessions.read(); | ||
| sessions.keys().copied().collect() | ||
| }; |
Comment on lines
131
to
136
| let batch: Vec<IpAddr> = ips_to_lookup | ||
| .into_iter() | ||
| .collect::<std::collections::HashSet<_>>() | ||
| .into_iter() | ||
| .take(MAX_CONCURRENT_LOOKUPS) | ||
| .collect(); |
Comment on lines
245
to
251
| // Perform parallel ASN lookups (limited batch size) | ||
| let batch: Vec<IpAddr> = ips_to_lookup | ||
| .into_iter() | ||
| .collect::<std::collections::HashSet<_>>() | ||
| .into_iter() | ||
| .take(MAX_CONCURRENT_LOOKUPS) | ||
| .collect(); |
Comment on lines
167
to
173
| // GeoIP lookups are fast (local file), so we can do more at once | ||
| let batch: Vec<IpAddr> = ips_to_lookup | ||
| .into_iter() | ||
| .collect::<std::collections::HashSet<_>>() | ||
| .into_iter() | ||
| .take(MAX_CONCURRENT_LOOKUPS) | ||
| .collect(); |
Comment on lines
672
to
678
| // Perform parallel IX lookups (limited batch size) | ||
| let batch: Vec<IpAddr> = ips_to_lookup | ||
| .into_iter() | ||
| .collect::<std::collections::HashSet<_>>() | ||
| .into_iter() | ||
| .take(MAX_CONCURRENT_LOOKUPS) | ||
| .collect(); |
Comment on lines
+532
to
+535
| fn flush_pending_as_timeouts(&self) { | ||
| let timed_out: Vec<_> = self.pending.write().drain().collect(); | ||
| self.record_pending_timeouts(timed_out, false, false); | ||
| } |
PMTUD probes and normal probes share the same ICMP identifier and ProbeId sequence space, so the receiver couldn't tell an Echo Reply for a PMTUD probe from one for a normal probe. When both a normal and PMTUD pending entry existed for the same (ProbeId, target), the receiver consumed the normal entry, causing the PMTUD probe to time out and the normal hop to receive spurious data. Fix: write a PMTUD marker (0x50) at payload byte 8 of ICMP Echo Requests. Echo Replies echo the payload verbatim, so the receiver can detect PMTUD success via parsed.is_pmtud. For Frag Needed / Packet Too Big (which quote the original packet, possibly truncated), the response type is still used as a fallback discriminator. - Add pmtud: bool parameter to build_echo_request - Add PMTUD_MARKER constant and is_pmtud field to ParsedResponse - Add is_pmtud_payload() helper to check marker in Echo Reply payload - Combine parsed.is_pmtud || response_type check for is_pmtud_response - Add 8 new tests: marker set/absent, min payload, Echo Reply routing, and end-to-end parse tests for DGRAM + RAW paths
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.
Summary
Fixes PMTUD probe correlation correctness, documents lock ordering, and deduplicates enrichment lookup targets.
Changes
#3 (high): PMTUD Echo Reply correlation via on-wire payload marker
PMTUD probes and normal probes share the same ICMP identifier and
ProbeIdsequence space. When both a normal and PMTUD pending entry existed for the same(ProbeId, target), the receiver couldn't distinguish which type of probe an Echo Reply was for. It preferred the normal entry, causing the PMTUD probe to time out andrecord_failure()to be called — leading to MTU under-estimation.Fix: Write a PMTUD marker byte (
0x50) at payload byte 8 of ICMP Echo Requests. Echo Replies echo the payload verbatim, so the receiver detects PMTUD success viaparsed.is_pmtud. For Frag Needed / Packet Too Big responses (which quote the original packet, possibly truncated to 8 bytes per RFC 792), the response type is used as a fallback discriminator:is_pmtud_response = parsed.is_pmtud || matches!(response_type, DestUnreachable(4) | PacketTooBig).build_echo_requestgains apmtud: boolparameter; when true, payload byte 8 is set toPMTUD_MARKER(0x50) instead of the normal pattern fill (0x00)ParsedResponsegains anis_pmtud: boolfield, set by checking the marker in Echo Reply payload viais_pmtud_payload()remove_pending_by_flow_hintroutes to the PMTUD pending entry whenis_pmtud_responseis true#10 (medium): Lock ordering documentation
Explicitly scopes the
sessions.read()guard in a nested block so it is dropped beforepending.write()is acquired in the receiver drain loop. Documents the lock order (sessionsbeforepending, never nested) to prevent future deadlock regressions.#12 (medium): Enrichment IP deduplication
Deduplicates IPs via
HashSetbeforetake(MAX_CONCURRENT_LOOKUPS)in all four enrichment workers (ASN, rDNS, GeoIP, IX). Previously, duplicate responder IPs across targets could occupy multiple concurrent lookup slots, wasting resources on redundant lookups.Testing
cargo clippy --all-targets -- -D warningsclean.test_pmtud_marker_set_in_payload/test_normal_probe_has_no_pmtud_marker— builder teststest_parse_pmtud_echo_reply_v4_dgram/test_parse_normal_echo_reply_v4_dgram/test_parse_pmtud_echo_reply_v4_raw— end-to-end parse tests that build a real Echo Request viabuild_echo_request, convert to Echo Reply, and verifyparsed.is_pmtudtest_remove_pending_unknown_flow_pmtud_echo_reply_prefers_pmtud_entry/test_remove_pending_unknown_flow_pmtud_echo_reply_no_flow_hint— pending removal routing teststest_remove_pending_explicit_flow_pmtud_response_prefers_pmtud— existing test updated for new signatureRisk
Medium — the PMTUD correlation change touches the receiver's probe-matching logic and adds a new on-wire byte (payload[8]). Normal probes set this to 0x00 (pattern fill), so there's no wire-protocol conflict. The marker is only checked for Echo Replies, not error responses (which may truncate the quoted payload).