MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / cleanup_stale_registrations

Function cleanup_stale_registrations

vmm/src/discovery.rs:113–144  ·  view source on GitHub ↗

Clean up stale discovery files from dead processes.

()

Source from the content-addressed store, hash-verified

111
112/// Clean up stale discovery files from dead processes.
113pub fn cleanup_stale_registrations() {
114 let dir = discovery_dir();
115 let entries = match std::fs::read_dir(dir) {
116 Ok(e) => e,
117 Err(_) => return,
118 };
119
120 for entry in entries.flatten() {
121 let path = entry.path();
122 if path.extension().and_then(|e| e.to_str()) != Some("json") {
123 continue;
124 }
125 let content = match std::fs::read_to_string(&path) {
126 Ok(c) => c,
127 Err(_) => continue,
128 };
129 let info: VmmInstanceInfo = match serde_json::from_str(&content) {
130 Ok(i) => i,
131 Err(_) => continue,
132 };
133 // Check if the process is still alive
134 let alive = Path::new(&format!("/proc/{}", info.pid)).exists();
135 if !alive {
136 info!(
137 "removing stale discovery file for pid {} at {}",
138 info.pid,
139 path.display()
140 );
141 let _ = std::fs::remove_file(&path);
142 }
143 }
144}

Callers 1

mainFunction · 0.85

Calls 2

discovery_dirFunction · 0.85
pathMethod · 0.80

Tested by

no test coverage detected