Skip to content

Commit

Permalink
- Runtime::close() now breaks cyclic references in self.router.tables…
Browse files Browse the repository at this point in the history
….tables.root_res
  • Loading branch information
DenisBiryukov91 committed Feb 1, 2024
1 parent eff8120 commit a6da9e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
10 changes: 10 additions & 0 deletions zenoh/src/net/routing/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,16 @@ impl Resource {
})
}

pub fn close(res: &mut Arc<Resource>) {
let r = get_mut_unchecked(res);
for (_s, c) in &mut r.childs {
Self::close(c);
}
r.parent.take();
r.childs.clear();
r.nonwild_prefix.take();
}

pub fn clean(res: &mut Arc<Resource>) {
let mut resclone = res.clone();
let mutres = get_mut_unchecked(&mut resclone);
Expand Down
26 changes: 12 additions & 14 deletions zenoh/src/net/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use super::routing::face::Face;
use super::routing::pubsub::full_reentrant_route_data;
use super::routing::router::{LinkStateInterceptor, Router};
use crate::config::{unwrap_or_default, Config, ModeDependent, Notifier};
use crate::net::routing::resource::Resource;
use crate::GIT_VERSION;
pub use adminspace::AdminSpace;
use async_std::task::JoinHandle;
Expand Down Expand Up @@ -205,20 +206,17 @@ impl Runtime {
drop(self.state.stop_source.write().unwrap().take());
self.manager().close().await;
// clean up to break cyclic reference of self.state to itself
self.router()
.tables
.tables
.write()
.unwrap()
.peers_net
.take();
self.router()
.tables
.tables
.write()
.unwrap()
.routers_net
.take();
let router = self.router();
let mut tables = router.tables.tables.write().unwrap();
tables.peers_net.take();
tables.routers_net.take();
tables.router_subs.clear();
tables.peer_subs.clear();
tables.router_qabls.clear();
tables.peer_qabls.clear();
Resource::close(&mut tables.root_res);

drop(tables);
self.state.transport_handlers.write().unwrap().clear();
Ok(())
}
Expand Down

0 comments on commit a6da9e8

Please sign in to comment.