Skip to content
Open
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
58 changes: 49 additions & 9 deletions ballista/executor/src/executor_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,48 @@ pub async fn start_executor_process_with_memory_metrics(
start_executor_process_inner(opt, Some(memory_metrics)).await
}

fn create_default_work_dir() -> ballista_core::error::Result<(String, TempDir)> {
let temp_dir = TempDir::new()?;

#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(
temp_dir.path(),
std::fs::Permissions::from_mode(0o700),
)?;
}

let path = temp_dir
.path()
.to_str()
.map(ToOwned::to_owned)
.ok_or_else(|| BallistaError::Configuration("Unable to bind work dir".into()))?;

Ok((path, temp_dir))
}

#[cfg(all(test, unix))]
mod default_work_dir_regression_tests {
use super::*;
use std::os::unix::fs::PermissionsExt;
use std::path::Path;

#[tokio::test]
async fn default_work_dir_survives_await_with_private_permissions() {
let (path, owner) = create_default_work_dir().unwrap();

tokio::task::yield_now().await;

assert!(Path::new(&path).is_dir());
let mode = std::fs::metadata(&path).unwrap().permissions().mode() & 0o777;
assert_eq!(mode, 0o700);

drop(owner);
assert!(!Path::new(&path).exists());
}
}

async fn start_executor_process_inner(
opt: Arc<ExecutorProcessConfig>,
memory_metrics: Option<ExecutorMemoryMetrics>,
Expand All @@ -522,15 +564,13 @@ async fn start_executor_process_inner(
let scheduler_port = opt.scheduler_port;
let scheduler_url = format!("http://{scheduler_host}:{scheduler_port}");

let work_dir = if let Some(work_dir) = opt.work_dir.clone() {
work_dir
} else if let Some(temp_dir) = TempDir::new()?.path().to_str().map(ToOwned::to_owned)
{
temp_dir
} else {
return Err(BallistaError::Configuration(
"Unable to bind work dir".to_string(),
));
// Keep the TempDir guard alive until the executor exits; otherwise startup removes the directory.
let (work_dir, _default_work_dir_owner) = match opt.work_dir.clone() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tiny suggestion. This binding is the whole fix, and renaming it to _ would quietly drop the guard again without the test noticing. Could you add a short comment here, something like "keep the guard alive until the executor exits, or the directory is deleted at startup"?

Some(work_dir) => (work_dir, None),
None => {
let (path, owner) = create_default_work_dir()?;
(path, Some(owner))
}
};

let vcores = if opt.vcores == 0 {
Expand Down