Skip to content
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

Memory leak in bound cache (stale entries) #106

Open
pbansalrubrik opened this issue Feb 17, 2024 · 0 comments
Open

Memory leak in bound cache (stale entries) #106

pbansalrubrik opened this issue Feb 17, 2024 · 0 comments

Comments

@pbansalrubrik
Copy link

Problem Description:
When Fiber to Socket create fiber, it add an entry in cache map (fiber id -> fiber object), however later it update the fiber id in fiber object and add another duplicate entry in cache map.
This result in accumulation of stale entries in cache map, since key of cache holds stale fiber id.
Also fiber is shared ptr, which means fiber never get released since a reference still exist in those stale entries.

Fix
Iterate through the cache_map to find entries which have same fiber object and prune them during connection reset handling.

Here is my code to fix the issue in file basic_fiber_demux_impl.hpp

void erase_fiber_and_used_ports(const fiber_id& id) { std::unique_lock<std::recursive_mutex> lock1(bound_mutex); std::unique_lock<std::recursive_mutex> lock2(used_ports_mutex); auto it = bound.begin(); while (it != bound.end()) { if (it->second->id == id) { // bound cache key is reverse of fid, that's why // we have to extract remote port which is local port of fiber fiber_id::local_port_type local_port = it->first.remote_port(); it = bound.erase(it); used_ports.erase(local_port); } else { ++it; } } }

Call this function erase_fiber_and_used_ports from
void basic_fiber_demux_service::unbind(implementation_type impl, const fiber_id& id)

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

No branches or pull requests

1 participant