Compare commits

...

3 Commits

Author SHA1 Message Date
R Tyler Croy 9a39ea00d6 Relocate the agent control socket to outside the current working directory
There was a race condition where sometimes the agent would set up the control
port so fast that a git into `.` would fail because the directory wasn't empty.

The better solution is to put the control socket outside the workspace in a temp
directory
2020-11-28 14:46:43 -08:00
R Tyler Croy 8b58f69b5e cargo update 2020-11-28 14:38:47 -08:00
R Tyler Croy 07f1dadea2 Ensure the agent exits with the right status to propagate failures up
Fixes #51
2020-11-28 14:38:26 -08:00
4 changed files with 25 additions and 15 deletions

8
Cargo.lock generated
View File

@ -175,9 +175,9 @@ dependencies = [
[[package]]
name = "async-io"
version = "1.2.0"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40a0b2bb8ae20fede194e779150fe283f65a4a08461b496de546ec366b174ad9"
checksum = "458c8f66c246624e7cf87c01451f3392ab77d66a0f105a49d9353b30ea97ced8"
dependencies = [
"concurrent-queue",
"fastrand",
@ -2303,9 +2303,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.51"
version = "1.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b4f34193997d92804d359ed09953e25d5138df6bcc055a71bf68ee89fdf9223"
checksum = "6c1e438504729046a5cfae47f97c30d6d083c7d91d94603efdae3477fc070d4c"
dependencies = [
"proc-macro2",
"quote",

View File

@ -78,9 +78,12 @@ async fn main() -> std::io::Result<()> {
panic!("Failed to parse parameters file: {:#?}", e);
}
Ok(invoke) => {
async_std::task::spawn(async {
let pipeline_uuid = invoke.pipeline.clone();
async_std::task::spawn(async move {
// TODO better error handling and behavior
control::run(sender).await.expect("Failed to bind control?");
control::run(pipeline_uuid, sender)
.await
.expect("Failed to bind control?");
});
/*
@ -93,9 +96,12 @@ async fn main() -> std::io::Result<()> {
set_common_env_vars();
run(&steps_dir, &invoke.steps, invoke.pipeline, Some(receiver))
let status = run(&steps_dir, &invoke.steps, invoke.pipeline, Some(receiver))
.expect("Failed to run pipeline");
println!("Agent exiting {:?}", status);
std::process::exit(status as i32);
}
};
Ok(())
}

View File

@ -5,6 +5,7 @@
use async_std::sync::Sender;
use log::*;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "type")]
@ -27,9 +28,9 @@ async fn handle_request(mut req: tide::Request<State>) -> tide::Result {
Ok("{}".into())
}
pub async fn run(sender: Sender<Request>) -> tide::Result<()> {
pub async fn run(pipeline: Uuid, sender: Sender<Request>) -> tide::Result<()> {
info!("Starting the agent control server");
let sock = agent_socket();
let sock = agent_socket(&pipeline);
let state = State { sender };
let mut app = tide::with_state(state);
@ -53,9 +54,11 @@ pub async fn run(sender: Sender<Request>) -> tide::Result<()> {
/**
* Return a string representing the absolute path of this agent's control socket
*/
pub fn agent_socket() -> std::path::PathBuf {
let path = std::env::current_dir().expect("Failed to get current directory");
path.join("agent.sock").to_path_buf()
pub fn agent_socket(pipeline: &Uuid) -> std::path::PathBuf {
let uuid = pipeline.to_hyphenated().to_string();
std::env::temp_dir()
.join(format!("{}-agent.sock", uuid))
.to_path_buf()
}
#[cfg(test)]
@ -64,7 +67,8 @@ mod tests {
#[test]
fn test_agent_sock() {
let buf = agent_socket();
let uuid = uuid::Uuid::new_v4();
let buf = agent_socket(&uuid);
assert!(buf.to_string_lossy().ends_with("agent.sock"));
}
}

View File

@ -188,7 +188,7 @@ pub fn run(
};
// TODO: This is going to be wrong on nested steps
let sock = control::agent_socket();
let sock = control::agent_socket(&pipeline);
let configuration = step::Configuration {
pipeline: pipeline,
uuid: step.uuid,