From 94c0878dbca078e721d18dc2845fba2134416ff1 Mon Sep 17 00:00:00 2001 From: Damien Date: Fri, 9 Sep 2022 14:40:53 +0100 Subject: [PATCH] fix: update meta DB state even on factory failure (#332) --- api/src/deployment.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/api/src/deployment.rs b/api/src/deployment.rs index 6c43901a3..89c079fd2 100644 --- a/api/src/deployment.rs +++ b/api/src/deployment.rs @@ -163,16 +163,24 @@ impl Deployment { meta.project.clone(), ); let addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), port); - match loader.load(&mut factory, addr, run_logs_tx, meta.id).await { + + let load_result = loader.load(&mut factory, addr, run_logs_tx, meta.id).await; + + // Even in case `load_result.is_err()`, we want to + // make sure `self.meta` reflects the latest of + // the state that was achieved through the + // phase. Otherwise we end up in a situation where + // a DB was provisioned, but the `meta` does not + // know about it. + self.meta.write().await.database_deployment = factory.into_database_info(); + + match load_result { Err(e) => { debug!("{}: factory phase FAILED: {:?}", meta.project, e); DeploymentState::Error(e.into()) } Ok((handle, so)) => { debug!("{}: factory phase DONE", meta.project); - self.meta.write().await.database_deployment = - factory.into_database_info(); - // Remove stale active deployments if let Some(stale_id) = context.router.promote(meta.host, meta.id).await {