{"record":{"id":"993068a6d3faa68d","repo":"apache/druid","slug":"unable-to-find-temp-file-s","errorCode":null,"errorMessage":"Unable to find temp file [%s]","messagePattern":"Unable to find temp file \\[(.+?)\\]","errorType":"exception","errorClass":"org.apache.druid.java.util.common.RE","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/storage/remote/ChunkingStorageConnector.java","lineNumber":196,"sourceCode":"                @Override\n                public void close() throws IOException\n                {\n                  // close should be idempotent\n                  if (fileInputStreamClosed.get()) {\n                    return;\n                  }\n                  fileInputStreamClosed.set(true);\n                  super.close();\n                  currentReadStartPosition.set(currentReadEndPosition);\n                  if (!outFile.delete()) {\n                    throw new RE(\"Cannot delete temp file [%s]\", outFile);\n                  }\n                }\n\n              };\n            }\n            catch (FileNotFoundException e) {\n              throw new RE(e, StringUtils.format(\"Unable to find temp file [%s]\", outFile));\n            }\n          }\n        }\n    )\n    {\n      @Override\n      public void close() throws IOException\n      {\n        isSequenceStreamClosed.set(true);\n        super.close();\n      }\n    };\n  }\n\n  public interface GetObjectFromRangeFunction<T>\n  {\n    T getObject(long start, long end);\n  }","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/storage/remote/ChunkingStorageConnector.java#L178-L214","documentation":"After creating the temp chunk file, the connector opens a FileInputStream on it. If the file vanished between creation and open (FileNotFoundException), it throws this RuntimeException 'Unable to find temp file [%s]'.","triggerScenarios":"nextElement() opens the temp file for reading but something deleted it in between — e.g. a concurrent cleanup of the temp directory, a second consumer's close() deleting the shared temp file, or an aggressive tmpwatch/systemd-tmpfiles sweep.","commonSituations":"Two consumers sharing one ChunkingStorageConnector stream where the first close deletes the file the second still needs; cron jobs cleaning /tmp during long segment reads; containers with short-lived tmpfs.","solutions":["Do not share a single chunked stream across threads; give each consumer its own copy/stream","Exclude Druid temp dirs from aggressive tmpwatch/tmpfiles cleanup schedules","Retry the segment fetch; if it recurs, check who is deleting files in the temp dir (audit with auditd/inotify)"],"exampleFix":"// before (shared)\nFileInputStream in = connector.getSegment(path);\nthreadA.consume(in); threadB.consume(in); // close deletes file used by B\n// after\ntry (FileInputStream a = connector.getSegment(path)) { threadA.consume(a); }\ntry (FileInputStream b = connector.getSegment(path)) { threadB.consume(b); }","handlingStrategy":"try-catch","validationCode":"if (!outFile.exists()) {\n  throw new FileNotFoundException(outFile.getPath());\n}","typeGuard":null,"tryCatchPattern":"catch (RuntimeException e) {\n  // file vanished before open: check temp-dir cleanup jobs, retry fetch\n}","preventionTips":["Never share one chunked stream or temp file across threads","Exclude Druid temp directories from tmpwatch/systemd-tmpfiles sweeps","Keep container tmpfs large enough and persistent for the copy duration"],"tags":["filesystem","temp-file","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}