upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 4fe5f15..b56f9f5 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -64,30 +64,38 @@ static string SockAccountingText()
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], nUntagged = 0;
65 BtfSockSnapshot(nOpened, nClosed, nFailed, &nUntagged); 65 BtfSockSnapshot(nOpened, nClosed, nFailed, &nUntagged);
66 66
67 long long nUnconn[SOCK_SITES];
68 BtfSockLiveUnconnected(nUnconn);
69
67 string str = "\n sockets by where they were created\n"; 70 string str = "\n sockets by where they were created\n";
68 str += " site opened closed live close failed\n"; 71 str += " site opened closed live close failed live unconn\n";
69 long long nTotalOpened = 0, nTotalClosed = 0, nTotalFailed = 0; 72 long long nTotalOpened = 0, nTotalClosed = 0, nTotalFailed = 0, nTotalUnconn = 0;
70 for (int i = 0; i < SOCK_SITES; i++) 73 for (int i = 0; i < SOCK_SITES; i++)
71 { 74 {
72 nTotalOpened += nOpened[i]; 75 nTotalOpened += nOpened[i];
73 nTotalClosed += nClosed[i]; 76 nTotalClosed += nClosed[i];
74 nTotalFailed += nFailed[i]; 77 nTotalFailed += nFailed[i];
78 nTotalUnconn += nUnconn[i];
75 if (nOpened[i] == 0) 79 if (nOpened[i] == 0)
76 continue; 80 continue;
77 str += strprintf(" %-24s %8lld %8lld %8lld %13lld\n", pszSockSite[i], 81 str += strprintf(" %-24s %8lld %8lld %8lld %13lld %12lld\n", pszSockSite[i],
78 nOpened[i], nClosed[i], nOpened[i] - nClosed[i], nFailed[i]); 82 nOpened[i], nClosed[i], nOpened[i] - nClosed[i], nFailed[i], nUnconn[i]);
79 } 83 }
80 str += strprintf(" %-24s %8s %8lld %8s %13s\n", "closed but never tagged", 84 str += strprintf(" %-24s %8s %8lld %8s %13s %12s\n", "closed but never tagged",
81 "-", nUntagged, "-", "-"); 85 "-", nUntagged, "-", "-", "-");
82 str += strprintf(" %-24s %8lld %8lld %8lld %13lld\n", "TOTAL", 86 str += strprintf(" %-24s %8lld %8lld %8lld %13lld %12lld\n", "TOTAL",
83 nTotalOpened, nTotalClosed, nTotalOpened - nTotalClosed, nTotalFailed); 87 nTotalOpened, nTotalClosed, nTotalOpened - nTotalClosed,
84 88 nTotalFailed, nTotalUnconn);
85 // The live total above is what this program believes it is holding. Compare 89
86 // it against what the operating system attributes to the process: on 90 // The live total is what this program believes it is holding. Comparing it
87 // Windows, `Get-NetTCPConnection | ? OwningProcess -eq <pid>`. A gap there 91 // against `Get-NetTCPConnection | ? OwningProcess -eq <pid>` needs the note
88 // is the leak, and the codes below say what the failed closes hit -- 10038 92 // in sockcount.h first: that table lists a wildcard-bound socket twice, so
89 // (WSAENOTSOCK) means the handle was already gone and this close was a 93 // a raw row count always looks larger than this. Count orphans, not rows.
90 // second one, which is a different bug from a descriptor that stayed. 94 //
95 // "live unconn" is a getpeername on every tagged socket. Anything above 1
96 // -- the listening socket -- means this program is holding a socket it
97 // never connected, which is the shape the leak hunt was looking for and
98 // never found.
91 if (nTotalFailed > 0) 99 if (nTotalFailed > 0)
92 { 100 {
93 str += " close failures by code\n"; 101 str += " close failures by code\n";