mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
fix(relay): reuse delete_allocation function (#1743)
Previously, we would access the state around allocations from different places. This actually led to a minor memory leak where we wouldn't clean up the `allocations_by_port` table. We refactor the code slightly to avoid this. --------- Co-authored-by: Jamil <jamilbk@users.noreply.github.com>
This commit is contained in:
@@ -47,7 +47,6 @@ pub struct Server<R> {
|
||||
|
||||
/// All client allocations, indexed by client's socket address.
|
||||
allocations: HashMap<SocketAddr, Allocation>,
|
||||
|
||||
clients_by_allocation: HashMap<AllocationId, SocketAddr>,
|
||||
allocations_by_port: HashMap<u16, AllocationId>,
|
||||
|
||||
@@ -450,23 +449,14 @@ where
|
||||
.ok_or(error_response(AllocationMismatch, &request))?;
|
||||
|
||||
if effective_lifetime.lifetime().is_zero() {
|
||||
let port = allocation.port;
|
||||
let id = allocation.id;
|
||||
|
||||
self.pending_commands
|
||||
.push_back(Command::FreeAddresses { id: allocation.id });
|
||||
self.allocations.remove(&sender);
|
||||
self.allocations_by_port.remove(&port);
|
||||
self.delete_allocation(id);
|
||||
self.send_message(
|
||||
refresh_success_response(effective_lifetime, request.transaction_id()),
|
||||
sender,
|
||||
);
|
||||
|
||||
tracing::info!(
|
||||
target: "relay",
|
||||
%port,
|
||||
"Deleted allocation"
|
||||
);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -743,9 +733,17 @@ where
|
||||
return;
|
||||
};
|
||||
|
||||
self.allocations.remove(&client);
|
||||
let allocation = self
|
||||
.allocations
|
||||
.remove(&client)
|
||||
.expect("internal state mismatch");
|
||||
let port = allocation.port;
|
||||
|
||||
self.allocations_by_port.remove(&port);
|
||||
self.pending_commands
|
||||
.push_back(Command::FreeAddresses { id });
|
||||
|
||||
tracing::info!(target: "relay", %port, "Deleted allocation");
|
||||
}
|
||||
|
||||
fn delete_channel_binding(&mut self, chan: u16) {
|
||||
|
||||
Reference in New Issue
Block a user