maxmind / MaxMind-DB-Reader-dotnet

.NET Reader for the MaxMind DB Database Format

Home Page:https://www.nuget.org/packages/MaxMind.Db

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slow memory leak.

electricessence opened this issue · comments

We are seeing a slow memory leak when using MaxMind GeoIP.
The underlying call uses Reader.

48 Hours

We are retaining the DatabaseReader as an instance for re-use. But for some reason there is a high amount of array retention when profiled.

As you can see in the chart, it's a very slow leak that is easy to miss if not monitored. Over time, this leak will consume memory until eventually an alert is triggered.

And to be sure, multiple people have looked over our code and there is no obvious point where we ourselves could be leaking. The pathway is synchronous and simply passes an IP and subsequently gets a city or country.

Some more context for above using DotMemory to profile our service (the snapshots are ~7 mins apart):

geotargetprofile

Off the top of my head, this dictionary is the only thing I can think of that could grow like this, but it should stop growing pretty quickly unless you were using this reader in a peculiar way and I don't think that corresponds to the additional context provided.

If you let the DatabaseReader go out of scope and be garbage collected, does the memory use go down? Which constructor are you using?

Although I think there may still be value in investigating this, I think it's compounded by other factors.
We've done an overhaul to eliminate this problem by properly hosting the data as a DI singleton and migrating it from a Azure Function to a dedicated service.