Skip to content

Commit c2690e7

Browse files
committed
fix: threaded connection leaks
Signed-off-by: Alexandre Rulleau <[email protected]>
1 parent 68a4326 commit c2690e7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

datadog-sidecar/src/unix.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,28 @@ pub fn shutdown_master_listener_unix() -> io::Result<()> {
112112

113113
if let Some((handle, fd)) = listener_data {
114114
stop_listening(fd);
115-
handle.join();
115+
116+
// Try to join with a timeout to avoid hanging the shutdown
117+
// We spawn a helper thread to do the join so we can implement a timeout
118+
let (tx, rx) = std::sync::mpsc::channel();
119+
std::thread::spawn(move || {
120+
let result = handle.join();
121+
let _ = tx.send(result);
122+
});
123+
124+
// Wait up to 2 seconds for clean shutdown (including time for tokio runtime shutdown)
125+
match rx.recv_timeout(Duration::from_millis(2000)) {
126+
Ok(Ok(())) => {
127+
// Clean shutdown
128+
}
129+
Ok(Err(_)) => {
130+
error!("Listener thread panicked during shutdown");
131+
}
132+
Err(_) => {
133+
// Timeout - thread didn't exit in time
134+
// This is acceptable as the OS will clean up when the process exits
135+
}
136+
}
116137
}
117138

118139
Ok(())

0 commit comments

Comments
 (0)