From 7f741f6a148f20249f3a30033ec525142f6e053a Mon Sep 17 00:00:00 2001 From: arjun12102019 Date: Thu, 30 May 2024 12:46:49 +0530 Subject: [PATCH] Changes for issue 14256 --- .../dubbo/common/cache/FileCacheStore.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java index 227289b1968..0687e280521 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java @@ -53,6 +53,7 @@ public class FileCacheStore { private final File cacheFile; private final File lockFile; private final FileLock directoryLock; + private static final int MAX_RETRIES = 3; private FileCacheStore(String cacheFilePath, File cacheFile, File lockFile, FileLock directoryLock) { this.cacheFilePath = cacheFilePath; @@ -150,10 +151,21 @@ private static void deleteFile(File f) { Path pathOfFile = f.toPath(); - try { - Files.delete(pathOfFile); - } catch (IOException ioException) { - logger.debug("Failed to delete file " + f.getAbsolutePath(), ioException); + for (int i = 0; i < MAX_RETRIES; i++) { + try { + Files.delete(pathOfFile); + if (!Files.exists(pathOfFile)) { + logger.debug("Successfully deleted file " + f.getAbsolutePath()); + return; + } + } catch (IOException ioException) { + logger.debug("Failed to delete file " + f.getAbsolutePath() + " on attempt " + (i + 1), ioException); + } + try { + Thread.sleep(1000); // Pause before retrying + } catch (InterruptedException e) { + logger.warn("Thread interrupted while waiting to retry file deletion", e); + } } }