SonarSource/sonarqube · warning
Failed to delete temp file
Error message
Failed to delete temp file {} What it means
This warning is logged by ReportSubmitter.deleteTempFile when a temporary report file written during CE task submission cannot be deleted. It is non-fatal: the report was already persisted (to DB or disk), so the submit proceeds; the warning only signals leaked temp files on disk.
Solutions
- Check the attached IOException message for the exact cause (permission denied vs no such file vs device busy)
- Verify the SonarQube temp directory (sonar.path.temp / OS temp) is writable by the SonarQube process user
- Exclude the SonarQube temp directory from antivirus/backup scanning that locks files mid-delete
- Manually clean leftover files in the temp directory during a maintenance window; repeated leaks only waste disk space
Example fix
// before chmod 755 /opt/sonarqube/temp # owned by root // after chown -R sonarqube:sonarqube /opt/sonarqube/temp && chmod 755 /opt/sonarqube/temp
Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure the temp directory is writable at startup
Path tmp = file.getParentFile().toPath();
if (!Files.isWritable(tmp)) throw new IllegalStateException("SonarQube temp dir not writable: " + tmp); Try / catch
// The code already swallows: mirror this when writing your own cleanup
try { Files.delete(path); }
catch (IOException e) { LOGGER.warn("Failed to delete temp file {}", path, e); } Prevention
- Exclude SonarQube temp dirs from AV/backup file locking
- Run SonarQube as a user owning its temp directory
- Set up disk-space and permissions monitoring on the temp volume
- Periodically clean stale files in sonar.path.temp during maintenance
When it happens
Trigger: saveReport/writePartToDb finishing a CE report upload and calling deleteTempFile, where Files.delete throws IOException: file already removed, permission denied, held open by a backup/AV process, or filesystem is read-only/full.
Common situations: Antivirus/indexers temporarily locking files on Windows; cleanup daemon racing the submitter; tmp directory permissions changed; disk-full states leaving deletions failing; containers with read-only tmp mounts.
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 temp file
- Can not delete
- Can not move file to
- Can not open file
- Can not unzip file to directory
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/22abf1d9eb60af70.
Report an issue: GitHub.
Appendix: source
Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java:338
} finally {
deleteTempFile(file);
}
}
private static void writePart(long byteSize, long partIndex, FileChannel sourceChannel, long reportPartMaxSizeBytes, File file) throws IOException {
try (RandomAccessFile toFile = new RandomAccessFile(file, "rw");
FileChannel toChannel = toFile.getChannel()
) {
sourceChannel.position(partIndex * reportPartMaxSizeBytes);
toChannel.transferFrom(sourceChannel, 0, byteSize);
}
}
private static void deleteTempFile(File file) {
try {
Files.delete(file.toPath());
} catch (IOException e) {
LOGGER.warn("Failed to delete temp file {}", file.getAbsolutePath(), e);
}
}
private void saveFileOnDb(DbSession dbSession, CeTaskSubmit.Builder submit, long partIndex, File file) {
long partNumber = partIndex + 1;
LOGGER.debug("Saving report {} part {} on DB from file {}", submit.getUuid(), partNumber, file.toPath());
try (InputStream is = Files.newInputStream(file.toPath())) {
dbClient.ceTaskInputDao().insert(dbSession, submit.getUuid(), partNumber, is);
} catch (IOException e) {
throw new IllegalStateException("Could not save report " + submit.getUuid() + " part " + partNumber + " file to database", e);
}
}
}
View on GitHub (pinned to 184c821202)