This is an automated email from the ASF dual-hosted git repository.
janhoy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new cc4b025b18d CATS: retry deletes that Windows refuses while a killed
process lets go (#5372)
cc4b025b18d is described below
commit cc4b025b18dca24d65ec255e3b50d8159676ed72
Author: Jan Høydahl <[email protected]>
AuthorDate: Sun Nov 22 00:14:02 2026 +0100
CATS: retry deletes that Windows refuses while a killed process lets go
(#5372)
---
.../java/org/apache/solr/cats/exec/CatsFiles.java | 33 ++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git
a/solr/test-framework/src/java/org/apache/solr/cats/exec/CatsFiles.java
b/solr/test-framework/src/java/org/apache/solr/cats/exec/CatsFiles.java
index 75818e79bf0..4a87d9a4cec 100644
--- a/solr/test-framework/src/java/org/apache/solr/cats/exec/CatsFiles.java
+++ b/solr/test-framework/src/java/org/apache/solr/cats/exec/CatsFiles.java
@@ -17,15 +17,20 @@
package org.apache.solr.cats.exec;
import java.io.IOException;
+import java.nio.file.FileSystemException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
+import java.time.Duration;
+import java.util.concurrent.TimeUnit;
/** File helpers for the harness, so the core needs no third-party IO library.
*/
public final class CatsFiles {
+ private static final Duration DELETE_RETRY_TIMEOUT = Duration.ofSeconds(5);
+
private CatsFiles() {}
/** Deletes a file, or a directory and everything below it. A missing path
is not an error. */
@@ -39,7 +44,7 @@ public final class CatsFiles {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes
attrs)
throws IOException {
- Files.deleteIfExists(file);
+ deleteRetrying(file);
return FileVisitResult.CONTINUE;
}
@@ -49,9 +54,33 @@ public final class CatsFiles {
if (failure != null) {
throw failure;
}
- Files.deleteIfExists(dir);
+ deleteRetrying(dir);
return FileVisitResult.CONTINUE;
}
});
}
+
+ /**
+ * Windows can keep a killed process's file handles open for a moment after
the process is
+ * reported dead, so a delete that fails is retried for a few seconds before
giving up.
+ */
+ private static void deleteRetrying(Path path) throws IOException {
+ long deadline = System.nanoTime() + DELETE_RETRY_TIMEOUT.toNanos();
+ while (true) {
+ try {
+ Files.deleteIfExists(path);
+ return;
+ } catch (FileSystemException e) {
+ if (System.nanoTime() >= deadline) {
+ throw e;
+ }
+ try {
+ TimeUnit.MILLISECONDS.sleep(100);
+ } catch (InterruptedException ie) {
+ Thread.currentThread().interrupt();
+ throw e;
+ }
+ }
+ }
+ }
}