Skip to content

Commit

Permalink
Moving reinstall function outside of promise.all (#82672)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-buttner committed Nov 5, 2020
1 parent 0cfcf9f commit f8f163c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion x-pack/plugins/ingest_manager/server/services/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(
Expand Down

0 comments on commit f8f163c

Please sign in to comment.