net: Add interrupt to pcp retry loop #33338
pull TheCharlatan wants to merge 1 commits into bitcoin:master from TheCharlatan:pcp_interrupt changing 5 files +36 −24-
TheCharlatan commented at 10:20 am on September 8, 2025: contributorWithout this interrupt bitcoind takes a long time to exit if requested to do so after a failed pcp lookup on startup.
-
net: Add interrupt to pcp retry loop
Without this interrupt bitcoind takes a long time to exit if requested to do so after a failed pcp lookup on startup.
-
DrahtBot added the label P2P on Sep 8, 2025
-
DrahtBot commented at 10:20 am on September 8, 2025: contributor
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Code Coverage & Benchmarks
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33338.
Reviews
See the guideline for information on the review process.
Type Reviewers ACK fjahr, hodlinator, achow101 If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
-
TheCharlatan commented at 10:21 am on September 8, 2025: contributor
Logs:
02025-09-08T10:02:52Z msghand thread start 12025-09-08T10:02:52Z Imported mempool transactions from file: 3 succeeded, 0 failed, 0 expired, 0 already there, 0 waiting for initial broadcast 22025-09-08T10:02:52Z initload thread exit 32025-09-08T10:02:52Z [net:warning] pcp: Could not receive response: Connection refused (111) 42025-09-08T10:02:52Z [net] portmap: gateway [IPv6]: fe80::a6ce:daff:fe8f:12a0%4 52025-09-08T10:02:52Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:4bfd:91da:7cba:67cb port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 62025-09-08T10:02:52Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:4bfd:91da:7cba:67cb 72025-09-08T10:02:53Z [net] trying v2 connection [2001:e60:1154:ccd9:3515:d56c:bb7:5f4c]:38333 lastseen=58.3hrs 82025-09-08T10:02:53Z [net] pcp: Timeout 92025-09-08T10:02:53Z [net] pcp: Retrying (1) 102025-09-08T10:02:54Z [net] pcp: Timeout 112025-09-08T10:02:54Z [net] pcp: Retrying (2) 12^C2025-09-08T10:02:54Z tor: Thread interrupt 132025-09-08T10:02:54Z Shutdown in progress... 142025-09-08T10:02:54Z torcontrol thread exit 152025-09-08T10:02:54Z dnsseed thread exit 162025-09-08T10:02:54Z addcon thread exit 172025-09-08T10:02:54Z net thread exit 182025-09-08T10:02:55Z msghand thread exit 192025-09-08T10:02:55Z [net] pcp: Timeout 202025-09-08T10:02:55Z [net] pcp: Giving up after 3 tries 212025-09-08T10:02:55Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:1386:bc1d:7d89:306d port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 222025-09-08T10:02:55Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:1386:bc1d:7d89:306d 232025-09-08T10:02:56Z [net] pcp: Timeout 242025-09-08T10:02:56Z [net] pcp: Retrying (1) 252025-09-08T10:02:57Z [net] pcp: Timeout 262025-09-08T10:02:57Z [net] pcp: Retrying (2) 272025-09-08T10:02:58Z [net] connection attempt to [2001:e60:1154:ccd9:3515:d56c:bb7:5f4c]:38333 timed out 282025-09-08T10:02:58Z opencon thread exit 292025-09-08T10:02:58Z [net] pcp: Timeout 302025-09-08T10:02:58Z [net] pcp: Giving up after 3 tries 312025-09-08T10:02:58Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:17ff:1c49:2591:5195 port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 322025-09-08T10:02:58Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:17ff:1c49:2591:5195 332025-09-08T10:02:59Z [net] pcp: Timeout 342025-09-08T10:02:59Z [net] pcp: Retrying (1) 352025-09-08T10:03:00Z [net] pcp: Timeout 362025-09-08T10:03:00Z [net] pcp: Retrying (2) 372025-09-08T10:03:01Z [net] pcp: Timeout 382025-09-08T10:03:01Z [net] pcp: Giving up after 3 tries 392025-09-08T10:03:01Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:5e43:d231:cd0b:5424 port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 402025-09-08T10:03:01Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:5e43:d231:cd0b:5424 412025-09-08T10:03:02Z [net] pcp: Timeout 422025-09-08T10:03:02Z [net] pcp: Retrying (1) 432025-09-08T10:03:03Z [net] pcp: Timeout 442025-09-08T10:03:03Z [net] pcp: Retrying (2) 452025-09-08T10:03:04Z [net] pcp: Timeout 462025-09-08T10:03:04Z [net] pcp: Giving up after 3 tries 472025-09-08T10:03:04Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:eb22:5bda:fe93:efb3 port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 482025-09-08T10:03:04Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:eb22:5bda:fe93:efb3 492025-09-08T10:03:05Z [net] pcp: Timeout 502025-09-08T10:03:05Z [net] pcp: Retrying (1) 512025-09-08T10:03:06Z [net] pcp: Timeout 522025-09-08T10:03:06Z [net] pcp: Retrying (2) 532025-09-08T10:03:07Z [net] pcp: Timeout 542025-09-08T10:03:07Z [net] pcp: Giving up after 3 tries 552025-09-08T10:03:07Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:ad0f:260a:2c63:7494 port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 562025-09-08T10:03:07Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:ad0f:260a:2c63:7494 572025-09-08T10:03:08Z [net] pcp: Timeout 582025-09-08T10:03:08Z [net] pcp: Retrying (1) 592025-09-08T10:03:09Z [net] pcp: Timeout 602025-09-08T10:03:09Z [net] pcp: Retrying (2) 612025-09-08T10:03:10Z [net] pcp: Timeout 622025-09-08T10:03:10Z [net] pcp: Giving up after 3 tries 632025-09-08T10:03:10Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:65cf:20cb:5921:45bf port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 642025-09-08T10:03:10Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:65cf:20cb:5921:45bf 652025-09-08T10:03:11Z [net] pcp: Timeout 662025-09-08T10:03:11Z [net] pcp: Retrying (1) 672025-09-08T10:03:12Z [net] pcp: Timeout 682025-09-08T10:03:12Z [net] pcp: Retrying (2) 692025-09-08T10:03:13Z [net] pcp: Timeout 702025-09-08T10:03:13Z [net] pcp: Giving up after 3 tries 712025-09-08T10:03:13Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:5f6b:1db9:7ba0:44a port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 722025-09-08T10:03:13Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:5f6b:1db9:7ba0:44a 732025-09-08T10:03:14Z [net] pcp: Timeout 742025-09-08T10:03:14Z [net] pcp: Retrying (1) 752025-09-08T10:03:15Z [net] pcp: Timeout 762025-09-08T10:03:15Z [net] pcp: Retrying (2) 772025-09-08T10:03:16Z [net] pcp: Timeout 782025-09-08T10:03:16Z [net] pcp: Giving up after 3 tries 792025-09-08T10:03:16Z [net] pcp: Requesting port mapping for addr 1111:1111::1 port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 802025-09-08T10:03:16Z [net] pcp: Internal address after connect: 1111:1111::1 812025-09-08T10:03:17Z [net] pcp: Timeout 822025-09-08T10:03:17Z [net] pcp: Retrying (1) 832025-09-08T10:03:18Z [net] pcp: Timeout 842025-09-08T10:03:18Z [net] pcp: Retrying (2) 852025-09-08T10:03:19Z [net] pcp: Timeout 862025-09-08T10:03:19Z [net] pcp: Giving up after 3 tries 872025-09-08T10:03:19Z mapport thread exit 882025-09-08T10:03:19Z [net] Flushed 13682 addresses to peers.dat 22ms 892025-09-08T10:03:19Z DumpAnchors: Flush 0 outbound block-relay-only peer addresses to anchors.dat started 902025-09-08T10:03:19Z DumpAnchors: Flush 0 outbound block-relay-only peer addresses to anchors.dat completed (0.01s) 912025-09-08T10:03:19Z scheduler thread exit 922025-09-08T10:03:19Z Writing 3 mempool transactions to file... 932025-09-08T10:03:19Z Writing 0 unbroadcast transactions to file. 942025-09-08T10:03:19Z Dumped mempool: 0.000s to copy, 0.008s to dump, 1011 bytes dumped to file 952025-09-08T10:03:19Z Flushed fee estimates to fee_estimates.dat. 962025-09-08T10:03:19Z Shutdown done
02025-09-08T10:07:03Z msghand thread start 12025-09-08T10:07:03Z addcon thread start 22025-09-08T10:07:03Z initload thread exit 32025-09-08T10:07:03Z [net:warning] pcp: Could not receive response: Connection refused (111) 42025-09-08T10:07:03Z [net] portmap: gateway [IPv6]: fe80::a6ce:daff:fe8f:12a0%4 52025-09-08T10:07:03Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:4bfd:91da:7cba:67cb port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 62025-09-08T10:07:03Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:4bfd:91da:7cba:67cb 7^C2025-09-08T10:07:03Z tor: Thread interrupt 82025-09-08T10:07:03Z Shutdown in progress... 92025-09-08T10:07:03Z torcontrol thread exit 102025-09-08T10:07:03Z addcon thread exit 112025-09-08T10:07:03Z opencon thread exit 122025-09-08T10:07:03Z dnsseed thread exit 132025-09-08T10:07:03Z net thread exit 142025-09-08T10:07:03Z msghand thread exit 152025-09-08T10:07:04Z [net] pcp: Timeout 162025-09-08T10:07:04Z [net] pcp: Retrying (1) 172025-09-08T10:07:04Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:1386:bc1d:7d89:306d port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 182025-09-08T10:07:04Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:1386:bc1d:7d89:306d 192025-09-08T10:07:04Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:17ff:1c49:2591:5195 port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 202025-09-08T10:07:04Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:17ff:1c49:2591:5195 212025-09-08T10:07:04Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:5e43:d231:cd0b:5424 port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 222025-09-08T10:07:04Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:5e43:d231:cd0b:5424 232025-09-08T10:07:04Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:eb22:5bda:fe93:efb3 port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 242025-09-08T10:07:04Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:eb22:5bda:fe93:efb3 252025-09-08T10:07:04Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:ad0f:260a:2c63:7494 port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 262025-09-08T10:07:04Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:ad0f:260a:2c63:7494 272025-09-08T10:07:04Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:65cf:20cb:5921:45bf port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 282025-09-08T10:07:04Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:65cf:20cb:5921:45bf 292025-09-08T10:07:04Z [net] pcp: Requesting port mapping for addr 2a02:1210:4a25:2f00:5f6b:1db9:7ba0:44a port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 302025-09-08T10:07:04Z [net] pcp: Internal address after connect: 2a02:1210:4a25:2f00:5f6b:1db9:7ba0:44a 312025-09-08T10:07:04Z [net] pcp: Requesting port mapping for addr 1111:1111::1 port 38333 from gateway fe80::a6ce:daff:fe8f:12a0%4 322025-09-08T10:07:04Z [net] pcp: Internal address after connect: 1111:1111::1 332025-09-08T10:07:04Z mapport thread exit 342025-09-08T10:07:04Z [net] Flushed 13692 addresses to peers.dat 20ms 352025-09-08T10:07:04Z DumpAnchors: Flush 0 outbound block-relay-only peer addresses to anchors.dat started 362025-09-08T10:07:04Z DumpAnchors: Flush 0 outbound block-relay-only peer addresses to anchors.dat completed (0.01s) 372025-09-08T10:07:04Z scheduler thread exit 382025-09-08T10:07:04Z Writing 3 mempool transactions to file... 392025-09-08T10:07:04Z Writing 0 unbroadcast transactions to file. 402025-09-08T10:07:04Z Dumped mempool: 0.000s to copy, 0.006s to dump, 1011 bytes dumped to file 412025-09-08T10:07:04Z Flushed fee estimates to fee_estimates.dat. 422025-09-08T10:07:04Z Shutdown done
-
fanquake added this to the milestone 30.0 on Sep 8, 2025
-
in src/common/pcp.cpp:222 in 188de70c86
217@@ -217,7 +218,8 @@ CNetAddr PCPUnwrapAddress(std::span<const uint8_t> wrapped_addr) 218 //! PCP or NAT-PMP send-receive loop. 219 std::optional<std::vector<uint8_t>> PCPSendRecv(Sock &sock, const std::string &protocol, std::span<const uint8_t> request, int num_tries, 220 std::chrono::milliseconds timeout_per_try, 221- std::function<bool(std::span<const uint8_t>)> check_packet) 222+ std::function<bool(std::span<const uint8_t>)> check_packet, 223+ CThreadInterrupt& interrupt)
hodlinator commented at 1:04 pm on September 8, 2025:nit: Would prefer keeping the lambda as the last parameter and also avoiding to mix
&
-placement within the same argument list.0 CThreadInterrupt &interrupt, 1 std::function<bool(std::span<const uint8_t>)> check_packet)
fjahr commented at 7:29 pm on September 8, 2025:CThreadInterrupt& interrupt
is our preferred style though (seePointerAlignment: Left
insrc/.clang-format
), so maybe we rather want to fix the other parameter to keep it consistent.in src/common/pcp.cpp:243 in 188de70c86
239@@ -238,6 +240,7 @@ std::optional<std::vector<uint8_t>> PCPSendRecv(Sock &sock, const std::string &p 240 auto cur_time = time_point_cast<milliseconds>(MockableSteadyClock::now()); 241 auto deadline = cur_time + timeout_per_try; 242 while ((cur_time = time_point_cast<milliseconds>(MockableSteadyClock::now())) < deadline) { 243+ if (interrupt) return std::nullopt;
fjahr commented at 2:51 pm on September 8, 2025:nit: comment above lists all the conditions for the wait to exit so it should list interrupt as well.in src/test/pcp_tests.cpp:18 in 188de70c86
14@@ -15,6 +15,8 @@ 15 16 using namespace std::literals; 17 18+static CThreadInterrupt g_interrupt;
fjahr commented at 2:52 pm on September 8, 2025:nit: Could add a simple test where the interrupt is instantly called to make sure the line is covered somehow.fjahr commented at 2:54 pm on September 8, 2025: contributorutACK 188de70c86414b8b2ad5143f5c607b67686526ea
Looks good to me, happy to re-review if you decide to address the nits.
hodlinator approvedhodlinator commented at 7:15 pm on September 8, 2025: contributorutACK 188de70c86414b8b2ad5143f5c607b67686526ea
Change just passes down
interrupt
for checking in inner loops.
Didn’t figure out a way of reproducing the behavior PR-author describes in #33338 (comment).
- Wasn’t able to bring to (zombie) life a local IPv6 gateway.
- Only have one ethernet interface on my local machine. Seems the author may have a handful.
- Reproduced something similar anyway through hacking this in:
…and testing Ctrl+C with/without interrupt/PR.
0diff --git a/src/common/pcp.cpp b/src/common/pcp.cpp 1index ed6624cb89..33b4c653fa 100644 2--- a/src/common/pcp.cpp 3+++ b/src/common/pcp.cpp 4@@ -246,9 +246,11 @@ std::optional<std::vector<uint8_t>> PCPSendRecv(Sock &sock, const std::string &p 5 LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "%s: Could not wait on socket: %s\n", protocol, NetworkErrorString(WSAGetLastError())); 6 return std::nullopt; // Network-level error, probably no use retrying. 7 } 8- if (!occurred) { 9+ std::this_thread::sleep_for(3s); 10+ //if (!occurred) { 11 LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "%s: Timeout\n", protocol); 12 break; // Retry. 13+ /* 14 } 15 16 // Receive response. 17@@ -263,6 +265,7 @@ std::optional<std::vector<uint8_t>> PCPSendRecv(Sock &sock, const std::string &p 18 got_response = true; // Got expected response, break from receive loop as well as from retry loop. 19 break; 20 } 21+ */ 22 } 23 } 24 if (!got_response) {
achow101 commented at 8:29 pm on September 8, 2025: memberACK 188de70c86414b8b2ad5143f5c607b67686526eaachow101 merged this on Sep 8, 2025achow101 closed this on Sep 8, 2025
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: 2025-10-10 15:13 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me