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

Detect and remove (deleted) suffix from hq binary path #792

Merged
merged 1 commit into from
Dec 19, 2024
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
29 changes: 27 additions & 2 deletions crates/hyperqueue/src/server/autoalloc/queue/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ pub struct ExternalHandler {

impl ExternalHandler {
pub fn new(server_directory: PathBuf, name: Option<String>) -> anyhow::Result<Self> {
let hq_path = std::env::current_exe().context("Cannot get HyperQueue path")?;
let hq_path =
normalize_exe_path(std::env::current_exe().context("Cannot get HyperQueue path")?);
Ok(Self {
server_directory,
hq_path,
Expand All @@ -40,6 +41,21 @@ impl ExternalHandler {
}
}

/// For some reason, Linux sometimes thinks that the current executable has been deleted,
/// and adds a ` (deleted)` suffix to its path.
/// That is quite annoying, so we get rid of that suffix.
/// See the following issues for more context:
/// - https://github.com/It4innovations/hyperqueue/issues/791
/// - https://github.com/It4innovations/hyperqueue/issues/452
fn normalize_exe_path(mut path: PathBuf) -> PathBuf {
if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
if let Some(name) = name.to_string().strip_suffix(" (deleted)") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_string is here to work around lifetimes.

path.set_file_name(name);
}
}
path
}

pub fn create_allocation_dir(
server_directory: PathBuf,
id: QueueId,
Expand Down Expand Up @@ -187,7 +203,8 @@ pub fn wrap_worker_cmd(

#[cfg(test)]
mod tests {
use crate::server::autoalloc::queue::common::wrap_worker_cmd;
use crate::server::autoalloc::queue::common::{normalize_exe_path, wrap_worker_cmd};
use std::path::PathBuf;

#[test]
fn wrap_cmd_noop() {
Expand Down Expand Up @@ -220,4 +237,12 @@ mod tests {
"init.sh && foo bar; unload.sh".to_string()
);
}

#[test]
fn normalize_deleted_path() {
assert_eq!(
normalize_exe_path(PathBuf::from("/a/b/c/hq (deleted)"),),
PathBuf::from("/a/b/c/hq")
);
}
}
Loading