{"record":{"id":"4cd9f456322ca6a4","repo":"apache/hadoop","slug":"failed-to-create-tmp-file","errorCode":null,"errorMessage":"failed to create tmp file","messagePattern":"failed to create tmp file","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/FileStore.java","lineNumber":204,"sourceCode":"      if (contentLength == 0) {\n        throw new NotAppendableException(String.format(\n            \"%s is not appendable because append non-existed object with \"\n                + \"zero byte is not supported.\", key));\n      }\n      return put(key, streamProvider, contentLength);\n    } else {\n      appendInputStreamToFile(streamProvider.newStream(), destFile, contentLength);\n      return ObjectInfo.isDir(key) ? Constants.MAGIC_CHECKSUM : getFileChecksum(destFile.toPath());\n    }\n  }\n\n  private static File createTmpFile(File destFile) {\n    String tmpFilename = \".tmp.\" + UUIDUtils.random();\n    File file = new File(destFile.getParentFile(), tmpFilename);\n\n    try {\n      if (!file.exists() && !file.createNewFile()) {\n        throw new RuntimeException(\"failed to create tmp file\");\n      }\n    } catch (IOException e) {\n      throw new RuntimeException(e);\n    }\n    return file;\n  }\n\n  @Override\n  public void delete(String key) {\n    Preconditions.checkArgument(!Strings.isNullOrEmpty(key), \"Key should not be empty.\");\n    File file = path(encode(key)).toFile();\n    if (file.exists()) {\n      try {\n        if (file.isDirectory()) {\n          FileUtils.deleteDirectory(file);\n        } else {\n          Files.delete(file.toPath());\n        }","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/FileStore.java#L186-L222","documentation":"FileStore.createTmpFile() stages every write through a hidden '.tmp.<random-uuid>' file next to the destination and throws this RuntimeException when createNewFile() returns false or throws IOException — i.e. the staging file could not be created in the destination's directory. Because all writes (put, part uploads, completeUpload) go through this helper, any failure to create a temp file surfaces here.","triggerScenarios":"put()/uploadPart()/completeUpload() reaching createTmpFile() when the destination's parent directory does not exist, is not writable, the filesystem is full, the process hit its open-file limit, or (rarely) the random name already exists and the exists() check raced.","commonSituations":"Filestore root or __STAGING__ subtree left in a bad state after a crashed run; test containers with a tiny tmpfs that fills up; ulimit -n exhausted by leaky test code; root directory deleted concurrently by cleanup code while uploads are in flight.","solutions":["Check free space and open-file limits on the volume backing the store root: df -h <root>, ulimit -n","Ensure the store root (and nothing else) owns the __STAGING__ subtree and it is writable: ls -ld <root>/__STAGING__","Restart the operation after cleaning stale .tmp.* files left by crashed runs: find <root> -name '.tmp.*' -delete","Verify no concurrent code deletes the root/staging directory while uploads are active (e.g. @After cleanup racing with async writers)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"java.io.File rootDir = new java.io.File(\n    conf.get(\"fs.filestore.endpoint\", System.getenv(\"FILE_STORAGE_ROOT\")));\nif (!rootDir.isDirectory() || !rootDir.canWrite()) {\n  throw new IOException(\"filestore root missing or not writable: \" + rootDir);\n}\nif (rootDir.getUsableSpace() < REQUIRED_FREE_BYTES) {\n  throw new IOException(\"low disk under filestore root: \" + rootDir);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-create the store root with Files.createDirectories() before initializing the FileStore","Give the store root a volume with headroom for staged data (uploads are staged as real files)","Raise ulimit -n / use fewer concurrent writers if open-file limits are near exhaustion","Sweep stale '.tmp.*' files after crashed runs so temp-file creation never collides"],"tags":["hadoop","tos","filestore","temp-file","local-storage"],"backgroundTag":"cannot-create-temp-file","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}