From 2a970954ba1687702c2c1a16e43e0fec365a73a0 Mon Sep 17 00:00:00 2001 From: Mark Hopkin Date: Thu, 19 Jan 2023 17:07:53 +0000 Subject: [PATCH] only retry on conflict errors --- .../fleet/server/services/epm/packages/install.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/epm/packages/install.ts b/x-pack/plugins/fleet/server/services/epm/packages/install.ts index c38bc77afd606..36bde4d4d0cbc 100644 --- a/x-pack/plugins/fleet/server/services/epm/packages/install.ts +++ b/x-pack/plugins/fleet/server/services/epm/packages/install.ts @@ -15,6 +15,7 @@ import type { SavedObjectsClientContract, Logger, } from '@kbn/core/server'; +import { SavedObjectsErrorHelpers } from '@kbn/core/server'; import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common/constants'; @@ -824,7 +825,7 @@ export const optimisticallyAddEsAssetReferences = async ( pkgName: string, assetsToAdd: EsAssetReference[] ): Promise => { - const addEsAsstes = async () => { + const addEsAssets = async () => { const so = await savedObjectsClient.get(PACKAGES_SAVED_OBJECT_TYPE, pkgName); const installedEs = so.attributes.installed_es ?? []; @@ -850,7 +851,13 @@ export const optimisticallyAddEsAssetReferences = async ( return updatedAssets ?? []; }; - return pRetry(addEsAsstes, { retries: 10 }); + const onlyRetryConflictErrors = (err: Error) => { + if (!SavedObjectsErrorHelpers.isConflictError(err)) { + throw err; + } + }; + + return pRetry(addEsAssets, { retries: 10, onFailedAttempt: onlyRetryConflictErrors }); }; export async function ensurePackagesCompletedInstall(