From 9de08fd8c3eb7b825153f6d2a960b18993f75616 Mon Sep 17 00:00:00 2001 From: iximeow Date: Fri, 30 Jun 2023 01:45:33 -0700 Subject: release db connection lock so as to not deadlock ci_driver afaict holding the lock over an await point gives tokio an opportunity to run a different task - perhaps a different API request that would try acquring the db connection lock. then it deadlocks; the second task holds the thread hostage while waiting for the first task to release its lock, which it can't do due to no thread being available for it to run on. --- src/ci_driver.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ci_driver.rs b/src/ci_driver.rs index c4a791d..0f629e7 100644 --- a/src/ci_driver.rs +++ b/src/ci_driver.rs @@ -71,6 +71,7 @@ async fn activate_job(dbctx: Arc, job: &PendingJob, clients: &mut mpsc::R let commit_sha: String = connection .query_row("select sha from commits where id=?1", [job.commit_id], |row| row.get(0)) .expect("can run query"); + std::mem::drop(connection); let artifacts: PathBuf = match &job.artifacts { Some(artifacts) => PathBuf::from(artifacts), @@ -126,11 +127,13 @@ async fn activate_job(dbctx: Arc, job: &PendingJob, clients: &mut mpsc::R let run_host = client_job.client.name.clone(); + let connection = dbctx.conn.lock().unwrap(); connection.execute( "update jobs set started_time=?1, run_host=?2, state=1, artifacts_path=?3, build_token=?4 where id=?5", (now as u64, run_host, format!("{}", artifacts.display()), &client_job.client.build_token, job.id) ) .expect("can update"); + std::mem::drop(connection); spawn(async move { client_job.run().await -- cgit v1.1