alibaba/nacos · warning · IOException
delete fail
Error message
delete fail
What it means
Thrown by IoUtils.delete(File) when File.delete() returns false for an existing regular file. delete() returning false (rather than throwing) is the JDK's signal that deletion did not succeed — typically because the file is locked, in use, or the caller lacks filesystem permission. The IOException carries no path detail, so you must know which file you passed.
Source
Thrown at common/src/main/java/com/alibaba/nacos/common/utils/IoUtils.java:237
* <p>If is dir, clean directory, do not delete dir.
*
* <p>If is file, delete file.
*
* @param fileOrDir file or dir
* @throws IOException io exception
*/
public static void delete(File fileOrDir) throws IOException {
if (fileOrDir == null) {
return;
}
if (fileOrDir.isDirectory()) {
cleanDirectory(fileOrDir);
} else {
if (fileOrDir.exists()) {
boolean isDeleteOk = fileOrDir.delete();
if (!isDeleteOk) {
throw new IOException("delete fail");
}
}
}
}
/**
* 清理目录下的内容. Clean content under directory.
*
* @param directory directory
* @throws IOException io exception
*/
public static void cleanDirectory(File directory) throws IOException {
if (!directory.exists()) {
String message = directory + " does not exist";
throw new IllegalArgumentException(message);
}
if (!directory.isDirectory()) {View on GitHub (pinned to 9b989acdf1)
Solutions
- Ensure all streams/channels to the file are closed (try-with-resources) before deleting.
- On Windows, retry deletion after a short delay once handles are released, or call System.gc() as a last resort to release mapped buffers.
- Verify the path is on a writable filesystem and the process has delete permission.
- Replace IoUtils.delete with Files.deleteIfExists + explicit attribute handling if you need richer diagnostics.
Example fix
// before
IoUtils.delete(file); // throws IOException("delete fail") if locked
// after
try { IoUtils.delete(file); }
catch (IOException e) {
if (!file.exists()) return; // already gone
// close any open handles, then retry with NIO
Files.deleteIfExists(file.toPath());
} Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure no open handles remain before deleting.
// (streams/channels must be closed via try-with-resources upstream)
if (fileOrDir != null && fileOrDir.exists() && !fileOrDir.isDirectory()) {
// safe to attempt delete
} Try / catch
try {
IoUtils.delete(file);
} catch (IOException e) {
if (!file.exists()) return; // already removed
try { Files.deleteIfExists(file.toPath()); }
catch (IOException ex) { throw new IOException("Cannot delete " + file, ex); }
} Prevention
- Close all streams/channels (try-with-resources) before deleting a file.
- On Windows, expect locked-file failures and retry or force GC of mapped buffers.
- Verify writable filesystem and delete permissions.
- Use Files.deleteIfExists for better diagnostics than the bare 'delete fail'.
When it happens
Trigger: Deleting a file that is still open by a stream/channel, locked by another process, on a read-only filesystem, or where the JVM lacks delete permission.
Common situations: Windows where open file handles block deletion; deleting a config/log file still being written; container read-only volume; concurrent process holding the file.
Related errors
- Failed to delete: {path}
- failed to create cache : {}{}
- {} does not exist
- {} is not a directory
- PARAMETER_VALIDATE_ERROR
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/eda0e6a8abead52c.
Report an issue: GitHub.