Skip to content

YARN-11829. Added retry to release file handler #7755

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,32 @@ public FSConfigConverterTestCommons() {

public void setUp() throws IOException {
File d = new File(TEST_DIR, "conversion-output");

if (d.exists()) {
FileUtils.deleteDirectory(d);
// Retry mechanism to ensure file handles are released
int maxRetries = 3;
int attempts = 0;
boolean deleted = false;

while (attempts < maxRetries && !deleted) {
try {
FileUtils.deleteDirectory(d);
deleted = true;
} catch (IOException e) {
attempts++;
System.gc(); // Hint JVM to run GC to close any unreferenced file streams
try {
Thread.sleep(100); // Wait a bit before retrying
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
if (attempts == maxRetries) {
throw new IOException("Failed to delete directory after retries: " + d.getAbsolutePath(), e);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This still may not guarantee the folder deletion. A better way to solve this would be to configure this class to never run the unit tests in parallel. You can use the @Execution(ExecutionMode.SAME_THREAD) annotation on the class in JUnit 5.

Could you please use an equivalent approach for the version of JUnit used here?

}

boolean success = d.mkdirs();
assertTrue(success, "Can't create directory: " + d.getAbsolutePath());
}
Expand Down