Skip to content

Commit 31f2cf5

Browse files
authored
remove signaling channels from listeners once used (#857)
We weren't cleaning up tokio channels from the `listeners` map in the `RouteMap`. This may have been the source of a memory leak we've noticed in the proxies starting a few months back.
1 parent db0a709 commit 31f2cf5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

plane/src/proxy/route_map.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ impl RouteMap {
105105
.lock()
106106
.expect("Routes lock was poisoned.")
107107
.push(token.clone(), route_info);
108-
let listener_lock = self.listeners.lock().expect("Listeners lock was poisoned.");
109-
if let Some(listener_lock) = listener_lock.get(&token) {
108+
let mut listener_lock = self.listeners.lock().expect("Listeners lock was poisoned.");
109+
if let Some(channel) = listener_lock.get(&token) {
110110
// We are just using the watch channel as a signal; this will ensure that anyone listening on `.changed()` resolves.
111-
listener_lock.send_modify(|()| ());
111+
channel.send_modify(|()| ());
112+
listener_lock.remove(&token);
112113
};
113114
}
114115

@@ -119,7 +120,7 @@ impl RouteMap {
119120
pub fn remove_backend(&self, backend: &BackendName) {
120121
// When a backend is terminated, we invalidate all routes that point to it.
121122
// We do this by looping over the connection tokens, but this is relatively inexpensive
122-
// because we have a maximum of 1,000 connection tokens in the LRU cache.
123+
// because we have a maximum of <CACHE_SIZE> connection tokens in the LRU cache.
123124
let mut count = 0;
124125
let mut lock = self.routes.lock().expect("Routes lock was poisoned.");
125126
for (_, maybe_route_info) in lock.iter_mut() {

0 commit comments

Comments
 (0)