From d46f8547a28fec9cddea30d7f54869a09ca86c0d Mon Sep 17 00:00:00 2001 From: Jonathan Buttner Date: Wed, 4 Nov 2020 18:25:36 -0500 Subject: [PATCH] Moving reinstall function outside of promise.all --- x-pack/plugins/ingest_manager/server/services/setup.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/ingest_manager/server/services/setup.ts b/x-pack/plugins/ingest_manager/server/services/setup.ts index 741a23824f010..ffdaaecd9eb04 100644 --- a/x-pack/plugins/ingest_manager/server/services/setup.ts +++ b/x-pack/plugins/ingest_manager/server/services/setup.ts @@ -58,7 +58,6 @@ async function createSetupSideEffects( ensureInstalledDefaultPackages(soClient, callCluster), outputService.ensureDefaultOutput(soClient), agentPolicyService.ensureDefaultAgentPolicy(soClient), - ensurePackagesCompletedInstall(soClient, callCluster), ensureDefaultIndices(callCluster), settingsService.getSettings(soClient).catch((e: any) => { if (e.isBoom && e.output.statusCode === 404) { @@ -70,6 +69,14 @@ async function createSetupSideEffects( }), ]); + // Keeping this outside of the Promise.all because it introduces a race condition. + // If one of the required packages fails to install/upgrade it might get stuck in the installing state. + // On the next call to the /setup API, if there is a upgrade available for one of the required packages a race condition + // will occur between upgrading the package and reinstalling the previously failed package. + // By moving this outside of the Promise.all, the upgrade will occur first, and then we'll attempt to reinstall any + // packages that are stuck in the installing state. + await ensurePackagesCompletedInstall(soClient, callCluster); + // If we just created the default policy, ensure default packages are added to it if (defaultAgentPolicyCreated) { const agentPolicyWithPackagePolicies = await agentPolicyService.get(