Tribler/py-ipv8

Memory leak in Network

egbertbouman opened this issue · 1 comments

When letting IPv8 run for about 1,5 days, I'm seeing a lot of IPv4 addresses in the Network class. For instance, in Network.reverse_intro_lookup I have 2009 keys (despite the 500 cache limit), while the total sum of all objects in the lists is 113163.

Memory leaks in other dicts within this class may also exist, but so far I've only seen issues with reverse_intro_lookup.

Note that despite these numbers, it takes a while before this actually has a significant impact on memory usage. This will only affect users who run IPv8 24/7.

Thanks for this report. It seems that the reverse_intro_lookup does not respect the cache size when adding peers here:

else:
self.reverse_intro_lookup[peer] = [address]

It is supposed to check the current cache size and pop old peers when the cache limit is reached, like this:

self.reverse_intro_lookup[peer] = introductions
if len(self.reverse_intro_lookup) > self.reverse_intro_cache_size:
self.reverse_intro_lookup.popitem(False) # Pop the oldest cache entry