apache/druid · error · org.apache.druid.java.util.common.RE

Unable to find temp file

Error message

Unable to find temp file [%s]

What it means

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]'.

Solutions

  1. Do not share a single chunked stream across threads; give each consumer its own copy/stream
  2. Exclude Druid temp dirs from aggressive tmpwatch/tmpfiles cleanup schedules
  3. Retry the segment fetch; if it recurs, check who is deleting files in the temp dir (audit with auditd/inotify)

Example fix

// before (shared)
FileInputStream in = connector.getSegment(path);
threadA.consume(in); threadB.consume(in); // close deletes file used by B
// after
try (FileInputStream a = connector.getSegment(path)) { threadA.consume(a); }
try (FileInputStream b = connector.getSegment(path)) { threadB.consume(b); }
Defensive patterns

Strategy: try-catch

Validate before calling

if (!outFile.exists()) {
  throw new FileNotFoundException(outFile.getPath());
}

Try / catch

catch (RuntimeException e) {
  // file vanished before open: check temp-dir cleanup jobs, retry fetch
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/993068a6d3faa68d. Report an issue: GitHub.

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/storage/remote/ChunkingStorageConnector.java:196

                @Override
                public void close() throws IOException
                {
                  // close should be idempotent
                  if (fileInputStreamClosed.get()) {
                    return;
                  }
                  fileInputStreamClosed.set(true);
                  super.close();
                  currentReadStartPosition.set(currentReadEndPosition);
                  if (!outFile.delete()) {
                    throw new RE("Cannot delete temp file [%s]", outFile);
                  }
                }

              };
            }
            catch (FileNotFoundException e) {
              throw new RE(e, StringUtils.format("Unable to find temp file [%s]", outFile));
            }
          }
        }
    )
    {
      @Override
      public void close() throws IOException
      {
        isSequenceStreamClosed.set(true);
        super.close();
      }
    };
  }

  public interface GetObjectFromRangeFunction<T>
  {
    T getObject(long start, long end);
  }

View on GitHub (pinned to 9b90983fd2)