Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent IPC socket cleanup panic #1312

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ struct Status {

impl Drop for IpcSocket {
fn drop(&mut self) {
log::info!("Removing IPC socket: {:?}", self.path);
std::fs::remove_file(&self.path).expect("Could not remove IPC socket");
self.try_remove_socket();
}
}

Expand Down Expand Up @@ -126,4 +125,14 @@ impl IpcSocket {
}
}
}

/// Try to remove the IPC socket if there is one for this instance of `ncspot`. Don't do
/// anything if the socket has already been removed for some reason.
fn try_remove_socket(&mut self) {
if std::fs::remove_file(&self.path).is_ok() {
info!("removed socket at {:?}", self.path);
} else {
info!("socket already removed");
}
}
}