TechnikEmpire / HttpFilteringEngine

Transparent filtering TLS proxy.
Mozilla Public License 2.0
59 stars 33 forks source link

We've really done it now - every connection will live forever in memory #136

Open TechnikEmpire opened 7 years ago

TechnikEmpire commented 7 years ago

At some unknown point in history, our use enable_shared_from_this has ended up causing every connection to get pinned in memory forever. Massive leak, unsure how this snuck by unnoticed for what appears to be some time.

TechnikEmpire commented 7 years ago

Even more interesting, a single destructor for ~TlsCapableHttpBridge() will get call on application exit, but not all the rest.

TechnikEmpire commented 7 years ago

I believe the cause of this is the use of lambda's for the async asio functions, where we use a shared_ptr self reference and pass it to the lambda via the capture list. This smells like the kind of situation that would pin a shared_ptr forever because you're defining it inside of a member function and capturing inside of another member function.

TechnikEmpire commented 7 years ago

Methinks the best solution here is to entirely eliminate shared_from_this and just have the acceptors keep instances to clients, and make them drop instances when a client flags itself as finito. This will avoid the problem both now and forever.

TechnikEmpire commented 7 years ago

Sigh, even if we do the above change, the asio reactor will hold on to callback references for an indeterminate period of time. If we allow this to expire while the reactor is still holding those callbacks, then we'll get a hard crash because the object is gone when the callback is finally invoked.