Skip to content

Commit

Permalink
fix: fix deadlock and reduce call to update_abbs
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Mar 21, 2024
1 parent 087c250 commit 15733a8
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions server/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ pub async fn pipeline_new(
return Err(anyhow!("Invalid branch: {git_branch}"));
}

let lock = ABBS_REPO_LOCK.lock().await;
update_abbs(git_branch, &ARGS.abbs_path)
.await
.context("Failed to update ABBS tree")?;

// resolve branch name to commit hash if not specified
let git_sha = match git_sha {
Some(git_sha) => {
Expand All @@ -85,11 +90,6 @@ pub async fn pipeline_new(
git_sha.to_string()
}
None => {
let _lock = ABBS_REPO_LOCK.lock().await;
update_abbs(git_branch, &ARGS.abbs_path)
.await
.context("Failed to update ABBS tree")?;

let output = tokio::process::Command::new("git")
.arg("rev-parse")
.arg("HEAD")
Expand All @@ -102,23 +102,17 @@ pub async fn pipeline_new(
};

// find environment requirements
let env_req = {
let resolved_pkgs = resolve_packages(
&packages
.split(",")
.map(|s| s.to_string())
.collect::<Vec<String>>(),
&ARGS.abbs_path,
)
.context("Resolve packages")?;
let resolved_pkgs = resolve_packages(
&packages
.split(",")
.map(|s| s.to_string())
.collect::<Vec<String>>(),
&ARGS.abbs_path,
)
.context("Resolve packages")?;

let _lock = ABBS_REPO_LOCK.lock().await;
update_abbs(git_branch, &ARGS.abbs_path)
.await
.context("Failed to update ABBS tree")?;

get_environment_requirement(&ARGS.abbs_path, &resolved_pkgs)
};
let env_req = get_environment_requirement(&ARGS.abbs_path, &resolved_pkgs);
drop(lock);

// create a new pipeline
let mut conn = pool
Expand Down Expand Up @@ -243,11 +237,6 @@ pub async fn pipeline_new_pr(
return Err(anyhow!("Failed to create job: Pull request is a fork"));
}

let _lock = ABBS_REPO_LOCK.lock().await;
update_abbs(git_branch, &ARGS.abbs_path)
.await
.context("Failed to update ABBS tree")?;

// find lines starting with #buildit
let packages = get_packages_from_pr(&pr);
if !packages.is_empty() {
Expand All @@ -256,6 +245,11 @@ pub async fn pipeline_new_pr(
} else {
let path = &ARGS.abbs_path;

let _lock = ABBS_REPO_LOCK.lock().await;
update_abbs(git_branch, &ARGS.abbs_path)
.await
.context("Failed to update ABBS tree")?;

let resolved_packages =
resolve_packages(&packages, path).context("Failed to resolve packages")?;

Expand Down

0 comments on commit 15733a8

Please sign in to comment.