net: reduce log level for PCP/NAT-PMP NOT_AUTHORIZED failures #34549

pull willcl-ark wants to merge 1 commits into bitcoin:master from willcl-ark:pcp-loglevel changing 1 files +25 −2
  1. willcl-ark commented at 2:12 pm on February 10, 2026: member

    Cherry-picks (and tweaks) a commit from #34117 which the ANAVHEOBA did not follow up with when changes were requested.

    The tweak here is to log once at LogWarning, so that users have a chance to spot misconfiguration.


    Users running on home networks with routers that don’t support PCP (Port Control Protocol) or NAT-PMP port mapping receive frequent warning-level log messages every few minutes:

    “pcp: Mapping failed with result NOT_AUTHORIZED (code 2)”

    This is expected behavior for many consumer routers that have PCP disabled by default, not an actionable error.

    Add explicit constants for the NOT_AUTHORIZED result code (value 2) for both NAT-PMP and PCP protocols. Log the first NOT_AUTHORIZED failure at warning level for visibility, then downgrade subsequent occurrences to LogDebug to avoid log noise. Other failure types continue to warn unconditionally.

    Fixes #34114

  2. DrahtBot added the label P2P on Feb 10, 2026
  3. DrahtBot commented at 2:13 pm on February 10, 2026: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK gmaxwell
    Stale ACK 0xB10C

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  4. fanquake commented at 3:15 pm on February 11, 2026: member
    cc @0xB10C
  5. fanquake added the label Needs backport (30.x) on Feb 11, 2026
  6. fanquake added this to the milestone 31.0 on Feb 11, 2026
  7. 0xB10C commented at 4:56 pm on February 11, 2026: contributor

    ACK 8fdca7d70de102cf3b0659fd8ca30e8d1e69062e

    I only get one [warning] pcp: Mapping failed with result NOT_AUTHORIZED (code 2) now and not multiple every 5 minutes. The NATPMP changes look Ok to me, but I hadn’t seen any logs for that before and now.

  8. net: reduce log level for PCP/NAT-PMP NOT_AUTHORIZED failures
    Users running on home networks with routers that don't support PCP (Port
    Control Protocol) or NAT-PMP port mapping receive frequent warning-level
    log messages every few minutes:
    
      "pcp: Mapping failed with result NOT_AUTHORIZED (code 2)"
    
    This is expected behavior for many consumer routers that have PCP
    disabled by default, not an actionable error.
    
    Add explicit constants for the NOT_AUTHORIZED result code (value 2)
    for both NAT-PMP and PCP protocols. Log the first NOT_AUTHORIZED
    failure at warning level for visibility, then downgrade subsequent
    occurrences to LogDebug to avoid log noise. Other failure types
    continue to warn unconditionally.
    
    Fixes #34114
    
    Co-authored-by: willcl-ark <will@256k1.dev>
    afea2af139
  9. in src/common/pcp.cpp:385 in 8fdca7d70d
    377@@ -374,7 +378,17 @@ std::variant<MappingResult, MappingError> NATPMPRequestPortMap(const CNetAddr &g
    378         Assume(response.size() >= NATPMP_MAP_RESPONSE_SIZE);
    379         uint16_t result_code = ReadBE16(response.data() + NATPMP_RESPONSE_HDR_RESULT_OFS);
    380         if (result_code != NATPMP_RESULT_SUCCESS) {
    381-            LogWarning("natpmp: Port mapping failed with result %s\n", NATPMPResultString(result_code));
    382+            if (result_code == NATPMP_RESULT_NOT_AUTHORIZED) {
    383+                static bool warned{false};
    384+                if (!warned) {
    385+                    LogWarning("natpmp: Port mapping failed with result %s\n", NATPMPResultString(result_code));
    386+                    warned = true;
    


    ajtowns commented at 11:42 pm on February 14, 2026:
    You’re modifying a global variable here with no particular assurances that this is only ever called from a single thread (should only be called via ThreadMapPort). Is there any reason not to at least declare/name these as the globals they are (bool g_warned_natpmp_failure) and add a comment about safety? Perhaps consider making them atomic.

    willcl-ark commented at 11:00 am on February 16, 2026:
    Thanks, even though it is only called from one thread currently, using an atomic is for sure better practice here. Switched to that in afea2af1391314be0e5caaa0125c884da2405316
  10. willcl-ark force-pushed on Feb 16, 2026
  11. gmaxwell commented at 5:51 am on February 17, 2026: contributor
    Concept ACK. I saw the PR subject line and came here to suggest that it log it verbosely just the first time, I think that’s exactly the right behavior.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-02-17 06:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me