-
Notifications
You must be signed in to change notification settings - Fork 210
Retry saving Agent information file (fleet.enc) on Windows
#9224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
328c91c
Retry saving Agent information file on Windows
ycombinator ec0029a
Implement retries on saving fleet.enc file
ycombinator 395a9de
Remove previous implementation
ycombinator fe62acd
Adding CHANGELOG file
ycombinator 553678b
Running mage fmt
ycombinator e20c50b
Remove unnecessary changes
ycombinator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
changelog/fragments/1754346816-fleet-enc-save-retries.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Kind can be one of: | ||
| # - breaking-change: a change to previously-documented behavior | ||
| # - deprecation: functionality that is being removed in a later release | ||
| # - bug-fix: fixes a problem in a previous version | ||
| # - enhancement: extends functionality but does not break or fix existing behavior | ||
| # - feature: new functionality | ||
| # - known-issue: problems that we are aware of in a given version | ||
| # - security: impacts on the security of a product or a user’s deployment. | ||
| # - upgrade: important information for someone upgrading from a prior version | ||
| # - other: does not fit into any of the other categories | ||
| kind: bug-fix | ||
|
|
||
| # Change summary; a 80ish characters long description of the change. | ||
| summary: On Windows, retry saving the Agent information file to disk | ||
|
|
||
| # Long description; in case the summary is not enough to describe the change | ||
| # this field accommodate a description without length limits. | ||
| # NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. | ||
| description: > | ||
| Saving the Agent information file involves renaming/moving a file to its final | ||
| destination. However, on Windows, it is sometimes not possible to rename/move a | ||
| file to its destination file because the destination file is locked by another | ||
| process (e.g. antivirus software). For such situations, we now retry the save operation | ||
| on Windows. | ||
| # Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc. | ||
| component: elastic-agent | ||
|
|
||
| # PR URL; optional; the PR number that added the changeset. | ||
| # If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. | ||
| # NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. | ||
| # Please provide it if you are adding a fragment for a different PR. | ||
| pr: https://github.com/elastic/elastic-agent/pull/9224 | ||
|
|
||
| # Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). | ||
| # If not present is automatically filled by the tooling with the issue linked to the PR number. | ||
| issue: https://github.com/elastic/elastic-agent/issues/5862 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
internal/pkg/agent/application/actions/handlers/handler_helpers_other.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
| // you may not use this file except in compliance with the Elastic License 2.0. | ||
|
|
||
| //go:build !windows | ||
|
|
||
| package handlers | ||
|
|
||
| import ( | ||
| "io" | ||
|
|
||
| "github.com/elastic/elastic-agent/pkg/core/logger" | ||
|
|
||
| "github.com/elastic/elastic-agent/internal/pkg/agent/storage" | ||
| ) | ||
|
|
||
| // saveConfigToStore saves the given configuration (reader) to the given store | ||
| func saveConfigToStore(store storage.Store, reader io.Reader, _ *logger.Logger) error { | ||
| return store.Save(reader) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
internal/pkg/agent/application/actions/handlers/handler_helpers_windows.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
| // you may not use this file except in compliance with the Elastic License 2.0. | ||
|
|
||
| //go:build windows | ||
|
|
||
| package handlers | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "io" | ||
| "syscall" | ||
| "time" | ||
|
|
||
| "github.com/cenkalti/backoff/v4" | ||
|
|
||
| "github.com/elastic/elastic-agent/internal/pkg/agent/storage" | ||
| "github.com/elastic/elastic-agent/pkg/core/logger" | ||
| ) | ||
|
|
||
| const saveRetryInterval = 50 * time.Millisecond | ||
| const saveRetryDuration = 2 * time.Second | ||
|
|
||
| // saveConfigToStore saves the given configuration (reader) to the given store. | ||
| // On Windows platforms, the save operation is retried if the error is an | ||
| // ACCESS_DENIED error, which can happen if the file is locked by another process. | ||
| func saveConfigToStore(store storage.Store, reader io.ReadSeeker, log *logger.Logger) error { | ||
| ctx, cancel := context.WithTimeout(context.Background(), saveRetryDuration) | ||
| defer cancel() | ||
|
|
||
| bo := backoff.WithContext(backoff.NewConstantBackOff(saveRetryInterval), ctx) | ||
|
|
||
| return backoff.Retry(func() error { | ||
| err := store.Save(reader) | ||
| if err == nil { | ||
| // Save succeeded | ||
| return nil | ||
| } | ||
|
|
||
| if !errors.Is(err, syscall.ERROR_ACCESS_DENIED) { | ||
| // Save failed due to an error that is not ACCESS_DENIED. Immediately | ||
| // indicate failure without retrying further. | ||
| log.Debugf("Saving configuration to store failed: %v. Not retrying.", err) | ||
| return backoff.Permanent(err) | ||
| } | ||
|
|
||
| if _, seekErr := reader.Seek(0, io.SeekStart); seekErr != nil { | ||
| log.Debugf("Saving configuration to store failed: %v. Failed to reset reader: %v. Not retrying.", err, seekErr) | ||
| return backoff.Permanent(errors.Join(err, seekErr)) | ||
| } | ||
|
|
||
| log.Debugf("Saving configuration to store failed: %v. Retrying...", err) | ||
| return err | ||
| }, bo) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.