diff options
| author | Bitflash <btf01@proton.me> | 2026-08-01 21:31:33 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-01 21:31:33 -0300 |
| commit | 5358e2396ca6cb371400f685181ef420dcf12382 (patch) | |
| tree | 6e5a363deafc74d315ad60857b8617d674b763f5 /src/net.cpp | |
| parent | ca0b6d0c4a3520a87037ba72bb1f1ee10eb504dc (diff) | |
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.
Diffstat (limited to 'src/net.cpp')
| -rw-r--r-- | src/net.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
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] = { | |||
| 61 | 61 | ||
| 62 | static string SockAccountingText() | 62 | static string SockAccountingText() |
| 63 | { | 63 | { |
| 64 | long long nOpened[SOCK_SITES], nClosed[SOCK_SITES], nFailed[SOCK_SITES], nUntagged = 0; | 64 | long long nOpened[SOCK_SITES], nClosed[SOCK_SITES], nFailed[SOCK_SITES]; |
| 65 | BtfSockSnapshot(nOpened, nClosed, nFailed, &nUntagged); | 65 | long long nCollided[SOCK_SITES], nUntagged = 0; |
| 66 | BtfSockSnapshot(nOpened, nClosed, nFailed, nCollided, &nUntagged); | ||
| 66 | 67 | ||
| 67 | long long nUnconn[SOCK_SITES]; | 68 | long long nUnconn[SOCK_SITES]; |
| 68 | BtfSockLiveUnconnected(nUnconn); | 69 | BtfSockLiveUnconnected(nUnconn); |
| @@ -112,6 +113,19 @@ static string SockAccountingText() | |||
| 112 | str += strprintf(" %-24s %s\n", pszSockSite[i], strCodes.c_str()); | 113 | str += strprintf(" %-24s %s\n", pszSockSite[i], strCodes.c_str()); |
| 113 | } | 114 | } |
| 114 | } | 115 | } |
| 116 | |||
| 117 | // A handle number handed out again while a site still claimed it. Windows | ||
| 118 | // only reuses a number after the last close, so this says that site's | ||
| 119 | // bookkeeping outlived its socket -- and it will close that number again, | ||
| 120 | // on somebody else's connection. Any value above zero is a bug with a name | ||
| 121 | // attached. | ||
| 122 | for (int i = 0; i < SOCK_SITES; i++) | ||
| 123 | { | ||
| 124 | if (nCollided[i] == 0) | ||
| 125 | continue; | ||
| 126 | str += strprintf(" handle reused while %s still claimed it: %lld\n", | ||
| 127 | pszSockSite[i], nCollided[i]); | ||
| 128 | } | ||
| 115 | return str; | 129 | return str; |
| 116 | } | 130 | } |
| 117 | 131 | ||