Skip to content

Commit

Permalink
Merge branch 'main' into feature/alex-update-new-container-resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
alexc-checkmarx authored Dec 26, 2024
2 parents af3f570 + 2fc507b commit 772f744
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions internal/commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2622,19 +2622,19 @@ func cleanUpTempZip(zipFilePath string) {
if zipFilePath != "" {
logger.PrintIfVerbose("Cleaning up temporary zip: " + zipFilePath)
tries := cleanupMaxRetries
for tries > 0 {
for attempt := 1; tries > 0; attempt++ {
zipRemoveErr := os.Remove(zipFilePath)
if zipRemoveErr != nil {
logger.PrintIfVerbose(
fmt.Sprintf(
"Failed to remove temporary zip: %d in %d: %v",
cleanupMaxRetries-tries,
"Failed to remove temporary zip: Attempt %d/%d: %v",
attempt,
cleanupMaxRetries,
zipRemoveErr,
),
)
tries--
time.Sleep(time.Duration(cleanupRetryWaitSeconds) * time.Second)
Wait(attempt)
} else {
logger.PrintIfVerbose("Removed temporary zip")
break
Expand All @@ -2648,6 +2648,13 @@ func cleanUpTempZip(zipFilePath string) {
}
}

func Wait(attempt int) {
// Calculate exponential backoff delay
waitDuration := time.Duration(cleanupRetryWaitSeconds * (1 << (attempt - 1))) // 2^(attempt-1)
logger.PrintIfVerbose(fmt.Sprintf("Waiting %d seconds before retrying...", waitDuration))
time.Sleep(waitDuration * time.Second)
}

func deprecatedFlagValue(cmd *cobra.Command, deprecatedFlagKey, inUseFlagKey string) string {
flagValue, _ := cmd.Flags().GetString(inUseFlagKey)
if flagValue == "" {
Expand Down

0 comments on commit 772f744

Please sign in to comment.