From 5358e2396ca6cb371400f685181ef420dcf12382 Mon Sep 17 00:00:00 2001 From: Bitflash Date: Sat, 1 Aug 2026 21:31:33 -0300 Subject: diag: catch a handle handed out while a site still claims it (#101) A live node reported one close failing with 10038 (WSAENOTSOCK) at the tunnel's pump end. It leaks nothing; what it says is that a site's bookkeeping and its sockets disagree about ownership -- and Windows reissues a handle number only after its last close, so a site whose bookkeeping outlives its socket will eventually close a number that belongs to a live connection. BtfSocketTag now counts a handle arriving while another site still claims it, which names the site to go and read. --- src/net.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/net.cpp') diff --git a/src/net.cpp b/src/net.cpp index b56f9f5..3af0189 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -61,8 +61,9 @@ static const char* pszSockSite[SOCK_SITES] = { static string SockAccountingText() { - long long nOpened[SOCK_SITES], nClosed[SOCK_SITES], nFailed[SOCK_SITES], nUntagged = 0; - BtfSockSnapshot(nOpened, nClosed, nFailed, &nUntagged); + long long nOpened[SOCK_SITES], nClosed[SOCK_SITES], nFailed[SOCK_SITES]; + long long nCollided[SOCK_SITES], nUntagged = 0; + BtfSockSnapshot(nOpened, nClosed, nFailed, nCollided, &nUntagged); long long nUnconn[SOCK_SITES]; BtfSockLiveUnconnected(nUnconn); @@ -112,6 +113,19 @@ static string SockAccountingText() str += strprintf(" %-24s %s\n", pszSockSite[i], strCodes.c_str()); } } + + // A handle number handed out again while a site still claimed it. Windows + // only reuses a number after the last close, so this says that site's + // bookkeeping outlived its socket -- and it will close that number again, + // on somebody else's connection. Any value above zero is a bug with a name + // attached. + for (int i = 0; i < SOCK_SITES; i++) + { + if (nCollided[i] == 0) + continue; + str += strprintf(" handle reused while %s still claimed it: %lld\n", + pszSockSite[i], nCollided[i]); + } return str; } -- cgit v1.2.3