8000 Fix memory leak in `ZKeydPool#invalidate` by kyri-petrou · Pull Request #9307 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix memory leak in ZKeydPool#invalidate #9307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 16, 2024

Conversation

kyri-petrou
Copy link
Contributor

/fixes #9306

The current behaviour of ZPool#invalidate is to add the invalidated item in a set which we then use to determine if an item that should be removed from the pool. This usage pattern can result in a memory leak when invalidate is called on items that are not present in the pool as they'll never be removed from the invalidated set.

I considered a few different implementations for this, but I ended up going with the simplest one I could think of

  • Instead of using a set to track the invalidated items, we use one to track the allocated items.
  • When we invalidate an item, we remove it from this set.
  • When we return / get an item from the pool, we check if the item is present in the allocated set, and if not that means it's been invalidated, so we remove it from the pool altogether

PS: I realised that the implementation of ZPool is rather inefficient at this moment and can be optimized. Since it's heavily used by ZIO HTTP's Client, I'll create a followup PR to optimize it

@kyri-petrou kyri-petrou merged commit c70afc4 into zio:series/2.x Nov 16, 2024
18 checks passed
@kyri-petrou kyri-petrou deleted the fix-zkeydpool-memory-leak branch November 16, 2024 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory leak in ZKeyedPool#invalidate
2 participants
0