MyCATApache/Mycat-Server · error · IOException
Failed to delete:
Error message
Failed to delete:
What it means
JavaUtils.deleteRecursively deletes a file or directory tree. It throws IOException when File.delete() fails (returns false) and the file still exists — e.g. due to a lock, permissions, or a non-empty directory handled elsewhere. Note delete() also returns false if the file never existed, which is why the exists() check is included.
Solutions
- Close any streams/locks or stop the process holding the file before deleting.
- Check and fix filesystem permissions on the file and its parent directory.
- Retain/inspect the exception's path to identify the specific file and delete it manually to see the OS error.
- Retry deletion after a short delay if a virus scanner or indexer transiently holds the file (common on Windows).
Example fix
// before
JavaUtils.deleteRecursively(tempDir);
// after
try {
JavaUtils.deleteRecursively(tempDir);
} catch (IOException e) {
logger.warn("Could not delete temp dir: " + e.getMessage());
} Defensive patterns
Strategy: try-catch
Validate before calling
if (file.exists() && !file.canWrite() && file.isDirectory()) {
// parent dir not writable — deletion will fail
} Try / catch
try {
JavaUtils.deleteRecursively(path);
} catch (IOException e) {
logger.warn("Failed to delete {}: {}", path, e.getMessage());
} Prevention
- Close all streams and file locks before deleting temp directories.
- Ensure the process user owns or has write permission on the files and parent dirs.
- On Windows, watch for antivirus/indexers holding files; retry after a delay.
- Catch and log cleanup failures instead of letting them mask primary errors.
When it happens
Trigger: Calling deleteRecursively on a path where the OS refuses deletion: read-only directory, file held open by another process (Windows), permission-denied, or an I/O error on the filesystem.
Common situations: Cleaning up temp directories while another thread/process still has files open; deleting files owned by another user; running on Windows with mapped/network drives; racing with a concurrent writer recreating files.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Failed to create local dir in $newDir.
- Failed to list files for dir:
- Mkdirs failed to create
- error while calling spill() on
- error while calling spill() on
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/718d4bc41f98b2ac.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/memory/unsafe/utils/JavaUtils.java:88
if (file.isDirectory() && !isSymlink(file)) {
IOException savedIOException = null;
for (File child : listFilesSafely(file)) {
try {
deleteRecursively(child);
} catch (IOException e) {
// In case of multiple exceptions, only last one will be thrown
savedIOException = e;
}
}
if (savedIOException != null) {
throw savedIOException;
}
}
boolean deleted = file.delete();
// Delete can also fail if the file simply did not exist.
if (!deleted && file.exists()) {
throw new IOException("Failed to delete: " + file.getAbsolutePath());
}
}
private static File[] listFilesSafely(File file) throws IOException {
if (file.exists()) {
File[] files = file.listFiles();
if (files == null) {
throw new IOException("Failed to list files for dir: " + file);
}
return files;
} else {
return new File[0];
}
}
private static boolean isSymlink(File file) throws IOException {
Preconditions.checkNotNull(file);
File fileInCanonicalDir = null;View on GitHub (pinned to 65f8d8beb7)