Repository navigation
fix(torrent): keep silent PCP probes from holding up port mapping removal - #590
Merged
Merged
Conversation
…oval stop() removed every requested mapping one after another, outermost first, within one 2 s budget. PCP MAP probes to guessed outer gateways are noted before they go out, and a removal sent to a gateway that never answered waited its whole 250 + 500 + 1000 ms schedule, so two of them used up the budget before the home router's mapping was asked to go, and the router kept forwarding the port until its lease ended. The probes also counted as NAT layers in the removal log, which then reported a layer that does not exist and said it may still forward the port. - Removals (at stop and when a pass prunes stale requests) go out side by side, so a silent gateway holds none of the others up. A pruned request is forgotten only once asked to go, so a stop that cuts it short sends it again. - Each request records whether its gateway answered: NAT-PMP and UPnP gateways did through discovery, a PCP gateway once a MAP got its reply. Until then its removal goes out once (PcpClient.map(once = true)). - The removal log counts only layers whose gateway answered, before or by confirming the removal.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Contributor
Test Results 2 101 files 2 129 suites 41m 52s ⏱️ Results for commit ad36af7. ♻️ This comment has been updated with latest results. |
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
A review of #587 found two problems in how the torrent port mapper removes its mappings when the engine stops. Both were older than #587.
The router's mapping is removed within the 2 s budget
stop()removed every requested mapping one at a time, outermost layer first, within one 2 s window.mapPcprecords a request before every PCP MAP probe it sends to a guessed outer gateway, including gateways that never answer.unmapAll), so a gateway that does not answer delays none of the others. The removal order made no difference to safety. A pass that prunes stale requests removes them the same way, and forgets a request only after its removal was sent, so astop()that interrupts the prune sends it again.Requested.answered):PcpClient.map(once = true), 250 ms).The removal log counts only real layers
Tests
NatLayersTestcase: a NAT-PMP home router whose WAN address is in carrier-grade NAT space (100.64.0.2), a silent PCP guess outside it, and a stop during that probe. The layer-0 mapping is removed within the default 2 s budget, the log reads "Removed the mapping of port 6881 through 1 NAT layer(s)", and the probe's removal is sent once. Against the old mapper this case fails with the "1 of 2 NAT layer(s)" line.:library:torrent:jvmTestand:library:torrent:compileTestKotlinIosSimulatorArm64pass locally.AGENTS.md and the port mapping details in
docs/torrent.mdare updated.