Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Add timeout to setup scripts #1659

Merged
merged 5 commits into from
Mar 1, 2022
Merged
Changes from 3 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
17 changes: 14 additions & 3 deletions src/agent/onefuzz-supervisor/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use std::path::{Path, PathBuf};
use std::process::Stdio;
use std::time::Duration;

use anyhow::{Context, Result};
use downcast_rs::Downcast;
Expand All @@ -13,6 +14,9 @@ use tokio::process::Command;

use crate::work::*;

// Default to 59 minutes, just under the service's `NODE_EXPIRATION_TIME` of 1 hour.
const DEFAULT_SETUP_SCRIPT_TIMEOUT: Duration = Duration::from_secs(59 * 60);

const SETUP_PATH_ENV: &str = "ONEFUZZ_TARGET_SETUP_PATH";

pub type SetupOutput = Option<Output>;
Expand Down Expand Up @@ -73,7 +77,7 @@ impl SetupRunner {
setup_script.path().display()
);

let output = setup_script.invoke().await?;
let output = setup_script.invoke(None).await?;

if output.exit_status.success {
debug!(
Expand Down Expand Up @@ -197,8 +201,15 @@ impl SetupScript {
&self.script_path
}

pub async fn invoke(&self) -> Result<Output> {
Ok(self.setup_command().output().await?.into())
pub async fn invoke(&self, timeout: impl Into<Option<Duration>>) -> Result<Output> {
let timeout = timeout.into().unwrap_or(DEFAULT_SETUP_SCRIPT_TIMEOUT);

let timed = tokio::time::timeout(timeout, self.setup_command().output())
.await
.context("setup script timed out")?;
let output = timed?.into();

Ok(output)
}

#[cfg(target_family = "windows")]
Expand Down