{"record":{"id":"22abf1d9eb60af70","repo":"SonarSource/sonarqube","slug":"failed-to-delete-temp-file","errorCode":null,"errorMessage":"Failed to delete temp file {}","messagePattern":"Failed to delete temp file (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java","lineNumber":338,"sourceCode":"    } finally {\n      deleteTempFile(file);\n    }\n  }\n\n  private static void writePart(long byteSize, long partIndex, FileChannel sourceChannel, long reportPartMaxSizeBytes, File file) throws IOException {\n    try (RandomAccessFile toFile = new RandomAccessFile(file, \"rw\");\n         FileChannel toChannel = toFile.getChannel()\n    ) {\n      sourceChannel.position(partIndex * reportPartMaxSizeBytes);\n      toChannel.transferFrom(sourceChannel, 0, byteSize);\n    }\n  }\n\n  private static void deleteTempFile(File file) {\n    try {\n      Files.delete(file.toPath());\n    } catch (IOException e) {\n      LOGGER.warn(\"Failed to delete temp file {}\", file.getAbsolutePath(), e);\n    }\n  }\n\n  private void saveFileOnDb(DbSession dbSession, CeTaskSubmit.Builder submit, long partIndex, File file) {\n    long partNumber = partIndex + 1;\n    LOGGER.debug(\"Saving report {} part {} on DB from file {}\", submit.getUuid(), partNumber, file.toPath());\n    try (InputStream is = Files.newInputStream(file.toPath())) {\n      dbClient.ceTaskInputDao().insert(dbSession, submit.getUuid(), partNumber, is);\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Could not save report \" + submit.getUuid() + \" part \" + partNumber + \" file to database\", e);\n    }\n  }\n\n}\n","sourceCodeStart":320,"sourceCodeEnd":353,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java#L320-L353","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nchmod 755 /opt/sonarqube/temp  # owned by root\n// after\nchown -R sonarqube:sonarqube /opt/sonarqube/temp && chmod 755 /opt/sonarqube/temp","handlingStrategy":"try-catch","validationCode":"// Ensure the temp directory is writable at startup\nPath tmp = file.getParentFile().toPath();\nif (!Files.isWritable(tmp)) throw new IllegalStateException(\"SonarQube temp dir not writable: \" + tmp);","typeGuard":null,"tryCatchPattern":"// The code already swallows: mirror this when writing your own cleanup\ntry { Files.delete(path); }\ncatch (IOException e) { LOGGER.warn(\"Failed to delete temp file {}\", path, e); }","preventionTips":["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"],"tags":["ce","temp-file","filesystem","cleanup","logging"],"backgroundTag":"file-write-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}