Minimize memory leaks when server is unreachable#350
Conversation
…Remove` via `DestroyPtr`
|
Tested on Linux x86-64 (Flatcar headless VM, no KVM, ~zero workload — just heartbeat to server). Compared the stock 2026-05-22 build against a build of this PR (HEAD Stock binary on this host showed the classic pattern:
( Replaced just the binary, no other changes:
RSS peak hasn't moved in the last ~38 h — clear plateau. Task count plateaus too (started at 2, jumped once to 36 around the 7 h mark, since then 36–37). CPU is ~41 min/day, same as the stock binary. Same workload, same MeshCentral server, same systemd config. The fix at |
This PR is related to #110 and is a best effort to clear some memory leaks.
Recently in our project we've also noticed high memory usage in cases where the server is unreachable. I did small review of the reconnection loop and implemented a couple of fixes and optimizations.
I did some tests for which I dodged the exponential backoff mechanism and forced the reconnections every 10ms. I noticed that even after a couple of hours the memory footprint is relatively low and much lower that when I tested the code from
masterto establish a baseline. There could be some more memory leaks lurking there, though.Quick summary of changes (details are in separate commits):
duk_gcduk_*functions which is now extracted toMeshServer_CheckAuthenticodewas leaking memory.Hope this helps.