njouanin / hbmqtt

MQTT client/broker using Python asynchronous I/O
MIT License
795 stars 188 forks source link

Broker memory leak for each client connection #207

Open shipmints opened 4 years ago

shipmints commented 4 years ago

As we're getting ready for production, we've been looking for things that would impact long-running processes including resource leaks. While we've patched a few so far (and submitted pull requests thank you @njouanin !), there is one persistent leak we can't find.

Whenever a client connects, a small amount of memory is leaked just about at the beginning of the asyncio server connection accept time. We've pretty much eliminated everything else from plugins to basic broker handling (but we could be wrong). We can't track down the leak. In case anyone is wondering, these are connections which reuse client_id so the session table remains stable in size. No client subscriptions are made and no messages need be transferred to observe the leak.

The leak is approximately 8-24 bytes each connection and it's hard to pin down the precise number of bytes if only because the memory footprint of a running broker is near 100% stable but not precisely 100%. This is not a showstopper for us as we will look to regularly reboot our server weekly or monthly.

That said, it would be satisfying to understand this leak should it be indicative of other issues that may arise. If anyone wants to take a look, or assist, perhaps with a commercial eye, that would be wonderful.