Skip to content

Added retry mechanism for close contentReader in download. #1099

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 3 commits into from
Apr 2, 2025

Conversation

agrasth
Copy link
Contributor

@agrasth agrasth commented Mar 18, 2025

Enhance Retry Mechanism for Content Reader Closure in Downloads
Summary:
This PR improves the reliability of the download process by introducing a retry mechanism when closing the contentReader.

Changes:
Added a retry mechanism to handle potential failures when closing the contentReader in the download process.


  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • All static analysis checks passed.
  • This pull request is on the dev branch.
  • I used gofmt for formatting the code before submitting the pull request.

func (cr *ContentReader) Close() error {
simulateError := false // Set to true in testing, and false in production

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this simulate error?
we can simply go ahead and retry

@@ -93,13 +98,43 @@ func (cr *ContentReader) Reset() {
cr.once = new(sync.Once)
}

// Cleanup the reader data.
// Retry function with forced error simulation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, we should create a general utility function for retry and pass a function along with comparables for the retry operation

// Simulate an error condition for the first few attempts if `simulateError` is true and attempts are less than maxForcedAttempts
if simulateError && downloadAttempts < maxForcedAttempts {
lastErr = fmt.Errorf("forced error simulation at attempt %d", downloadAttempts+1)
downloadAttempts++

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we referring download here, aren't you just trying to close a opened file?

log.Info("Operation succeeded at attempt %d", i+1)
return nil
}
log.Warn("Retry attempt %d failed: %v", i+1, lastErr)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.Warn("Retry attempt %d failed: %v", i+1, lastErr)
log.Warn("Retry attempt %d failed: %v", i+1, lastErr.Error())

return nil
}
log.Warn("Retry attempt %d failed: %v", i+1, lastErr)
time.Sleep(time.Millisecond * 100) // Adding a small delay between retries

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is sleep required?

@fluxxBot
Copy link

I was able to see the same issue here, please check if this could be of any help.
cc: @agrasth @bhanurp

@agrasth agrasth force-pushed the addRetryMechanisms branch from ce2f37b to 17f0c68 Compare April 2, 2025 10:35
@bhanurp bhanurp added the safe to test Approve running integration tests on a pull request label Apr 2, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Apr 2, 2025
Copy link
Contributor

github-actions bot commented Apr 2, 2025

👍 Frogbot scanned this pull request and did not find any new security issues.


@agrasth agrasth merged commit 6a376a9 into jfrog:dev Apr 2, 2025
24 checks passed
@EyalDelarea EyalDelarea added the improvement Automatically generated release notes label Apr 10, 2025
EyalDelarea pushed a commit to EyalDelarea/jfrog-client-go that referenced this pull request Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Automatically generated release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants