From 1bb49c37e0425f314b8a93b011a71cf7f07e8db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 18 Mar 2022 11:42:13 +0000 Subject: [PATCH] Improve build container cleanup --- app/executor.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/executor.php b/app/executor.php index 1fa32599a..cd501c90d 100644 --- a/app/executor.php +++ b/app/executor.php @@ -306,9 +306,24 @@ App::post('/v1/runtimes') Console::error('Build failed: ' . $th->getMessage() . $stdout); throw new Exception($th->getMessage() . $stdout, 500); } finally { - if (!empty($containerId) && $remove) { - $orchestration->remove($containerId, true); + // Container cleanup + if($remove) { + if (!empty($containerId)) { + // If container properly created + $orchestration->remove($containerId, true); + } else { + // If whole creation failed, but container might have been initialized + try { + // Try to remove with contaier name instead of ID + $orchestration->remove($runtimeId, true); + } catch (Throwable $th) { + // If fails, means initialization also failed. + // Contianer is not there, no need to remove + } + } } + + // Release orchestration back to pool, we are done with it $orchestrationPool->put($orchestration); }