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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions utils/io/content/contentreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package content

import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"github.com/jfrog/gofrog/http/retryexecutor"
"github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/log"
Expand Down Expand Up @@ -93,14 +96,34 @@ func (cr *ContentReader) Reset() {
cr.once = new(sync.Once)
}

// Cleanup the reader data.
func removeFileWithRetry(filePath string) error {
// Check if file exists before attempting to remove
if _, err := os.Stat(filePath); os.IsNotExist(err) {
log.Debug("File does not exist: %s", filePath)
return nil
}
log.Debug("Attempting to remove file: %s", filePath)
executor := retryexecutor.RetryExecutor{
Context: context.Background(),
MaxRetries: 5,
RetriesIntervalMilliSecs: 100,
ErrorMessage: "Failed to remove file",
LogMsgPrefix: "Attempting removal",
ExecutionHandler: func() (bool, error) {
return false, errorutils.CheckError(os.Remove(filePath))
},
}
return executor.Execute()
}

// Cleanup the reader data with retry
func (cr *ContentReader) Close() error {
for _, filePath := range cr.filesPaths {
if filePath == "" {
continue
}
if err := errorutils.CheckError(os.Remove(filePath)); err != nil {
return errors.New("Failed to close reader: " + err.Error())
if err := removeFileWithRetry(filePath); err != nil {
return fmt.Errorf("failed to close reader: %w", err)
}
}
cr.filesPaths = nil
Expand Down