Skip to content

PMP requests continue even if library throws error #10486

Closed

Description

@redfast00

What happened?

If err != nil, not in all cases is nil returned:

syncthing/lib/pmp/pmp.go

Lines 53 to 61 in bc7e56f

if err != nil {
if errors.Is(err, context.Canceled) {
return nil
}
if strings.Contains(err.Error(), "Timed out") {
slog.Debug("Timeout trying to get external address, assume no NAT-PMP available")
return nil
}
}

and https://github.com/jackpal/go-nat-pmp/blob/master/natpmp.go#L121

My router responds with version = 2 packets (PCP instead of PMP), so go-nat-pmp throws an error (https://github.com/jackpal/go-nat-pmp/blob/master/natpmp.go#L121). This should normally result in an error in syncthing, but the checking code in pmp.go does not return nil in all error cases.

Suggestion: do return nil in all error cases, and log error; that way, it would have been a lot easier to see that my router only supports v2 (PCP) instead of having to look at a network dump.

I suspect that because of this, upnp is also not tried when the PMP code looks fine.

Syncthing version

v2.0.12

Platform & operating system

Linux amd64

Browser version

No response

Relevant log output

Activity

  1. added
    bug
    on Dec 9, 2025
  2. added theissue type on Dec 9, 2025
  3. added
    needs-triage
    on Dec 9, 2025
  4. mango766 commented on Mar 16, 2026

    @mango766

    Hi, I took a look at this and I think you're right -- the error handling in Discover() has a gap where non-timeout errors fall through without returning nil. This means a wrapper device gets created for a gateway that doesn't actually speak NAT-PMP.

    I've put up a fix in #10607 that moves the return nil outside the inner conditional branches so all error cases are handled. It also adds a debug log line for non-timeout errors, which should make it easier to diagnose situations like yours where the router only supports PCP.

  5. added a commit that references this issue on Apr 22, 2026
    b1ccf3f
  6. added a commit that references this issue on Jun 28, 2026
    a4dadaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triage

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions