openjdk/jdk · error · IOException

Failed to delete file.

Error message

Failed to delete file.

What it means

IOException from PortFile.delete(): the server-side port file could not be deleted after 10 attempts spaced 1 second apart. The retry loop exists deliberately — an undeleted port file would make subsequent clients try to talk to a dead server, so the deletion failure is treated as fatal for the shutdown sequence.

Source

Thrown at make/langtools/tools/javacserver/shared/PortFile.java:183

        rwfile.writeLong(cookie);
        myServerPort = port;
        myServerCookie = cookie;
    }

    /**
     * Delete the port file.
     */
    public void delete() throws IOException, InterruptedException {
        if (!file.exists()) { // file deleted already
            return;
        }
        // Keep trying until file has been deleted, otherwise we
        // might shutdown the server and prevent another one from starting.
        for (int i = 0; i < 10 && file.exists() && !file.delete(); i++) {
            Thread.sleep(1000);
        }
        if (file.exists()) {
            throw new IOException("Failed to delete file.");
        }
        // allow some time for late clients to connect
        Thread.sleep(1000);
    }

    /**
     * Is the port file still there?
     */
    public boolean exists() throws IOException {
        return file.exists();
    }

    /**
     * Is a stop file there?
     */
    public boolean markedForStop() throws IOException {
        if (stopFile.exists()) {
            try {

View on GitHub (pinned to 88dfb74bbe)

Solutions

  1. Ensure the user running the shutdown owns the port file's directory and has write permission on it.
  2. Terminate all javacserver clients and processes before shutting the server down.
  3. Manually remove the port file (rm) once no processes reference it, and retry the build.
  4. On Windows, close any IDEs/builds that may hold the file open.

Example fix

# before: shutdown fails because the port file is locked
server-stop

# after: release holders, then remove manually
pkill -f javacserver
rm -f /path/to/javacserver.port
server-stop
Defensive patterns

Strategy: retry

Validate before calling

// before delete(): ensure nothing else is holding the file
if (file.exists() && !file.canWrite())
    throw new IOException("port file not deletable (permissions): " + file);

Try / catch

try {
    portFile.delete();
} catch (IOException e) {
    if (System.getProperty("os.name").toLowerCase().contains("win")) {
        // Windows lock: schedule deletion on exit rather than failing shutdown
        file.deleteOnExit();
    } else {
        Files.deleteIfExists(file.toPath()); // one NIO attempt with real errno
        throw e;
    }
}

Prevention

When it happens

Trigger: Server shutdown calling delete() when another process holds the file open with semantics that block unlink (Windows), the containing directory is not writable, or an external tool (antivirus, indexer) keeps recreating/locking the file.

Common situations: Windows builds where a concurrent client has the port file mapped/locked; NFS semantics preventing deletion; the port file directory owned by root after a sudo build.

Related errors


AI-assisted analysis of openjdk/jdk@88dfb74bbe (2026-08-14). Data as JSON: /api/errors/1506c21401f1c559. Report an issue: GitHub.