diff options
| author | Bitflash <btf01@proton.me> | 2026-08-01 18:43:25 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-01 18:43:25 -0300 |
| commit | 2ffc50998c30f285f45c5c5d81975bf857885aa8 (patch) | |
| tree | 9fe6be3a0dd7a8f869c88f9c1dd13e75fa8e7b78 /src/net.cpp | |
| parent | 19ecd6ad61b560d92d82ed5a79b5217d64f97327 (diff) | |
diag: say why a close failed, and total what the program thinks it holds (#98)
The 1.2.11 accounting answered 'which site' and stopped. On a node with 3h51m of uptime it reported 58 live sockets while Windows attributed 112 to the process, 47 of them bound and never connected, against 55 closes that had returned an error -- with nothing recording what those errors were. Close failures are now counted per code per site, and the table totals, so the live figure can be compared directly against what the OS attributes to the process. Instrumentation only.
Diffstat (limited to 'src/net.cpp')
| -rw-r--r-- | src/net.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp index 7a13257..4fe5f15 100644 --- a/src/net.cpp +++ b/src/net.cpp | |||
| @@ -66,8 +66,12 @@ static string SockAccountingText() | |||
| 66 | 66 | ||
| 67 | string str = "\n sockets by where they were created\n"; | 67 | string str = "\n sockets by where they were created\n"; |
| 68 | str += " site opened closed live close failed\n"; | 68 | str += " site opened closed live close failed\n"; |
| 69 | long long nTotalOpened = 0, nTotalClosed = 0, nTotalFailed = 0; | ||
| 69 | for (int i = 0; i < SOCK_SITES; i++) | 70 | for (int i = 0; i < SOCK_SITES; i++) |
| 70 | { | 71 | { |
| 72 | nTotalOpened += nOpened[i]; | ||
| 73 | nTotalClosed += nClosed[i]; | ||
| 74 | nTotalFailed += nFailed[i]; | ||
| 71 | if (nOpened[i] == 0) | 75 | if (nOpened[i] == 0) |
| 72 | continue; | 76 | continue; |
| 73 | str += strprintf(" %-24s %8lld %8lld %8lld %13lld\n", pszSockSite[i], | 77 | str += strprintf(" %-24s %8lld %8lld %8lld %13lld\n", pszSockSite[i], |
| @@ -75,6 +79,31 @@ static string SockAccountingText() | |||
| 75 | } | 79 | } |
| 76 | str += strprintf(" %-24s %8s %8lld %8s %13s\n", "closed but never tagged", | 80 | str += strprintf(" %-24s %8s %8lld %8s %13s\n", "closed but never tagged", |
| 77 | "-", nUntagged, "-", "-"); | 81 | "-", nUntagged, "-", "-"); |
| 82 | str += strprintf(" %-24s %8lld %8lld %8lld %13lld\n", "TOTAL", | ||
| 83 | nTotalOpened, nTotalClosed, nTotalOpened - nTotalClosed, nTotalFailed); | ||
| 84 | |||
| 85 | // The live total above is what this program believes it is holding. Compare | ||
| 86 | // it against what the operating system attributes to the process: on | ||
| 87 | // Windows, `Get-NetTCPConnection | ? OwningProcess -eq <pid>`. A gap there | ||
| 88 | // is the leak, and the codes below say what the failed closes hit -- 10038 | ||
| 89 | // (WSAENOTSOCK) means the handle was already gone and this close was a | ||
| 90 | // second one, which is a different bug from a descriptor that stayed. | ||
| 91 | if (nTotalFailed > 0) | ||
| 92 | { | ||
| 93 | str += " close failures by code\n"; | ||
| 94 | for (int i = 0; i < SOCK_SITES; i++) | ||
| 95 | { | ||
| 96 | if (nFailed[i] == 0) | ||
| 97 | continue; | ||
| 98 | map<int, long long> mapErr; | ||
| 99 | BtfSockCloseErrors(i, mapErr); | ||
| 100 | string strCodes; | ||
| 101 | for (map<int, long long>::const_iterator mi = mapErr.begin(); mi != mapErr.end(); ++mi) | ||
| 102 | strCodes += strprintf("%s%d x%lld", strCodes.empty() ? "" : ", ", | ||
| 103 | mi->first, mi->second); | ||
| 104 | str += strprintf(" %-24s %s\n", pszSockSite[i], strCodes.c_str()); | ||
| 105 | } | ||
| 106 | } | ||
| 78 | return str; | 107 | return str; |
| 79 | } | 108 | } |
| 80 | 109 | ||