Skip to content

Commit be28e8e

Browse files
[8.18] [Fleet] Add install retry to ensureInstalledPackage (#224265) (#224418)
# Backport This will backport the following commits from `main` to `8.18`: - [[Fleet] Add install retry to ensureInstalledPackage (#224265)](#224265) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Jill Guyonnet","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-06-18T12:23:47Z","message":"[Fleet] Add install retry to ensureInstalledPackage (#224265)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/213337\n\nWhen requests to install a package as part of the logic ensuring that a\npackage is installed are fired concurrently, the second request fails\nwith a 409 `version_conflict_engine_exception`, which causes flakiness\nin tests. Ignoring these errors in transform installs was already\nattempted in #177380. This PR adds\na retry mechanism directly into the package install to consolidate the\nflow.\n\n### Identify risks\n\nLow probability risk of slower package policy creation.","sha":"62f56c884b87e953ef9d6c09e693a70691c28c09","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","backport:prev-minor","backport:prev-major","v9.1.0"],"title":"[Fleet] Add install retry to ensureInstalledPackage","number":224265,"url":"https://github.com/elastic/kibana/pull/224265","mergeCommit":{"message":"[Fleet] Add install retry to ensureInstalledPackage (#224265)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/213337\n\nWhen requests to install a package as part of the logic ensuring that a\npackage is installed are fired concurrently, the second request fails\nwith a 409 `version_conflict_engine_exception`, which causes flakiness\nin tests. Ignoring these errors in transform installs was already\nattempted in #177380. This PR adds\na retry mechanism directly into the package install to consolidate the\nflow.\n\n### Identify risks\n\nLow probability risk of slower package policy creation.","sha":"62f56c884b87e953ef9d6c09e693a70691c28c09"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/224265","number":224265,"mergeCommit":{"message":"[Fleet] Add install retry to ensureInstalledPackage (#224265)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/213337\n\nWhen requests to install a package as part of the logic ensuring that a\npackage is installed are fired concurrently, the second request fails\nwith a 409 `version_conflict_engine_exception`, which causes flakiness\nin tests. Ignoring these errors in transform installs was already\nattempted in #177380. This PR adds\na retry mechanism directly into the package install to consolidate the\nflow.\n\n### Identify risks\n\nLow probability risk of slower package policy creation.","sha":"62f56c884b87e953ef9d6c09e693a70691c28c09"}}]}] BACKPORT--> Co-authored-by: Jill Guyonnet <[email protected]>
1 parent 0ca1e4d commit be28e8e

File tree

1 file changed

+28
-10
lines changed
  • x-pack/platform/plugins/shared/fleet/server/services/epm/packages

1 file changed

+28
-10
lines changed

x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ import { removeInstallation } from './remove';
106106

107107
export const UPLOAD_RETRY_AFTER_MS = 10000; // 10s
108108
const MAX_ENSURE_INSTALL_TIME = 60 * 1000;
109+
const MAX_INSTALL_RETRIES = 5;
110+
const BASE_RETRY_DELAY_MS = 1000; // 1s
109111

110112
const PACKAGES_TO_INSTALL_WITH_STREAMING = [
111113
// The security_detection_engine package contains a large number of assets and
@@ -212,16 +214,32 @@ export async function ensureInstalledPackage(options: {
212214
};
213215
}
214216
const pkgkey = Registry.pkgToPkgKey(pkgKeyProps);
215-
const installResult = await installPackage({
216-
installSource: 'registry',
217-
savedObjectsClient,
218-
pkgkey,
219-
spaceId,
220-
esClient,
221-
neverIgnoreVerificationError: !force,
222-
force: true, // Always force outdated packages to be installed if a later version isn't installed
223-
authorizationHeader,
224-
});
217+
218+
const installPackageWithRetries = async (attempt: number): Promise<InstallResult> => {
219+
const installResult = await installPackage({
220+
installSource: 'registry',
221+
savedObjectsClient,
222+
pkgkey,
223+
spaceId,
224+
esClient,
225+
neverIgnoreVerificationError: !force,
226+
force: true, // Always force outdated packages to be installed if a later version isn't installed
227+
authorizationHeader,
228+
});
229+
230+
if (
231+
attempt < MAX_INSTALL_RETRIES &&
232+
installResult.error?.message.includes('version_conflict_engine_exception')
233+
) {
234+
const delayMs = BASE_RETRY_DELAY_MS * 2 ** attempt; // Exponential backoff
235+
await new Promise((resolve) => setTimeout(resolve, delayMs));
236+
return await installPackageWithRetries(++attempt);
237+
} else {
238+
return installResult;
239+
}
240+
};
241+
242+
const installResult = await installPackageWithRetries(0);
225243

226244
if (installResult.error) {
227245
const errorPrefix =

0 commit comments

Comments
 (0)