portmapper: synchronous HomeRouter lookup blocks the Tokio worker

Open
#266 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@TNTcraftHIM is already working on this.

Since Nov 2, 2026.

  • #268 by @TNTcraftHIM — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
50/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
networking

Research direction

Start in the portmapper async service, where HomeRouter::new() is called synchronously before probing or creating a mapping, and check the existing private helpers that the proposal would await. Run the reduced probe_keeps_timers_running control on a current_thread runtime to reproduce the blocked timer. Done means HomeRouter::new runs under spawn_blocking, task failure maps to ProbeError::Join, the public API is unchanged, and the timer completes near 100 ms.

Written by the indexing model from the issue text.

Description

ready-for-pr

In portmapper 0.20.0, the async service calls synchronous HomeRouter::new() before probing or creating a mapping. A slow interface/gateway lookup can stall unrelated tasks on that Tokio worker.

On Windows, a public-API control with all three mapping protocols disabled delayed a 100 ms timer to 1,154 ms. With the lookup on spawn_blocking, the same timer completed in 101 ms while lookup was still pending. These are local observations, not a portable timing guarantee. Current main still has the same gateway code.

Would moving HomeRouter::new to spawn_blocking, awaiting it through the existing private helpers, and mapping task failure to ProbeError::Join be acceptable? This would keep the public API and protocol selection unchanged. It is separate from the UPnP socket teardown in #236/#254 and the already-offloaded WMI default-route call in #124.

The one-file release-based candidate passes cargo +1.91.0 check --locked -p portmapper.

Reduced public-API control
#[tokio::test(flavor = "current_thread")]
async fn probe_keeps_timers_running() {
    let client = portmapper::Client::new(portmapper::Config {
        enable_upnp: false,
        enable_pcp: false,
        enable_nat_pmp: false,
        protocol: portmapper::Protocol::Udp,
    });
    let _probe = client.probe();
    let started = std::time::Instant::now();
    tokio::time::sleep(std::time::Duration::from_millis(100)).await;
    eprintln!("100 ms timer: {:?}", started.elapsed());
}

The observed delay depends on the machine's gateway lookup; this control does not establish its duration on other systems.

Dominant language
Rust
Stars
34
Forks
56
Avg merge
2d 4h
Merged PRs (30d)
8

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from n0-computer/net-tools

All issues in n0-computer/net-tools

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.