Memory leak detected within DmnExecutionContext class
jrosellr opened this issue · comments
Hi! While working with the DmnExecutionContext
class I have found a possible memory leak related with the property ParsedExpressionsCache
. When creating multiple execution contexts the stale cache entries related to out of scope contexts are not removed, staying permanently cached even though the context to which are related no longer exists.
This causes a memory leak when a long running application creates multiple instances of DmnExecutionContext
, like a webapi creating a new context per request.
Hi @JoanRosell, thanks for the hint, you're absolutely right. The cache scopes was a quick and apparently very dirty fix of a scoping problem.
Fix idea:
The Execution and Context cache should not be stored in static property as they can live within the context instance and follow its lifecycle (plus purging the Execution cache at the end of the execution).
Definition cache purging is a bit more tricky as there is no "hard boundaries" lifecycle. As of now, I'm not sure whether to store the Definition cache within the definition (it doesn't feel good pattern so far as it will mix the definition and execution domains) or whether to implement some purge method (I also don't really like it as it "externalize" the responsibility). I need to think a bit about.
Anyway, thanks again for the hint, I'll prepare the fix for the next patch.
Cool, thank you very much for your quick reply! I'll be looking forward to the fix. I'll tackle this issue if I get some spare time this week to help out.
Hi @JoanRosell , the first draft is in github-issue-15-cache-lifecycle branch.
So far, the Definition cache doesn't have the "auto-managed" lifecycle, just the purge method
Hi @JoanRosell,
I added some additional tests and updated the documentation related to the fix in github-issue-15-cache-lifecycle branch.
I think this is all for the fix and I'll squash it like this into the next patch whenever it's gonna be released.
Feel free to check and provide a feed back if anything comes to your mind.
Thanks
Radek
Edit - attaching the package with the dev build
net.adamec.lib.common.dmn.engine.1.0.2-dev.903.220209235221.nupkg.zip
Hello again, do you have an estimate of when you will make a new official release?
Hi @JoanRosell, currently working on the version 1.1 that will also contain the fix. I expect the release during the May.
Cool, thank you very much for your fast response!
Hi @JoanRosell , the Release v1.1.0 is out, the updated package is also already at NuGet
Nice! I'll close this issue once we run some load tests just to double check.
Superb, thanks!
Hi @JoanRosell , just for the information - I found some "non-compatibility" with OMG standard related to diagram related functionality that might block parsing valid DMN XML models in some cases, so I published the patch
Hi @JoanRosell, just checking whether do you have any updates from your testing or I can close the issue.
Thanks
Hi @adamecr, everything is looking fine! After having it running on production for some weeks now I can safely say that the issue is resolved. I'm closing the issue right now, keep up the good work!
Hi @JoanRosell, great to hear! Thanks a lot for reporting the issue and the feedback.