{"record":{"id":"a65a5e754892da8a","repo":"apache/beam","slug":"unable-to-delete-local-heap-dump","errorCode":null,"errorMessage":"Unable to delete local heap dump {}","messagePattern":"Unable to delete local heap dump (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sdks/java/harness/src/main/java/org/apache/beam/fn/harness/status/MemoryMonitor.java","lineNumber":361,"sourceCode":"        LOG.warn(\n            \"Heap dump {} of {}MB detected, attempting to upload file to {}\",\n            localSource,\n            localSource.length() / 1024 / 1024,\n            remoteDest);\n        ResourceId resource = FileSystems.matchNewResource(remoteDest, false);\n        try {\n          uploadFile(localSource, resource, gzipCompress);\n          uploadedHeapDump = true;\n          LOG.warn(\"Heap dump {} uploaded to {}\", localSource, remoteDest);\n        } catch (IOException e) {\n          LOG.error(\"Error uploading heap dump to {}\", remoteDest, e);\n        }\n\n        try {\n          Files.delete(localSource.toPath());\n          LOG.info(\"Deleted local heap dump {}\", localSource);\n        } catch (IOException e) {\n          LOG.warn(\"Unable to delete local heap dump {}\", localSource, e);\n        }\n      }\n    }\n\n    return uploadedHeapDump;\n  }\n\n  private void uploadFile(File srcPath, ResourceId destination, boolean gzipCompress)\n      throws IOException {\n    StandardCreateOptions createOptions =\n        StandardCreateOptions.builder().setMimeType(\"application/octet-stream\").build();\n    try (WritableByteChannel dst = FileSystems.create(destination, createOptions);\n        ReadableByteChannel src = Channels.newChannel(new FileInputStream(srcPath))) {\n      if (gzipCompress) {\n        try (OutputStream os = new GZIPOutputStream(Channels.newOutputStream(dst));\n            WritableByteChannel gzipDst = Channels.newChannel(os)) {\n          ByteStreams.copy(src, gzipDst);\n        }","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/status/MemoryMonitor.java#L343-L379","documentation":"Warning logged when Files.delete on the local heap dump file fails with IOException after an upload attempt. The dump was (or was not) uploaded but could not be cleaned up from local disk, potentially wasting worker disk space. Upload outcome is unaffected; the method returns based on the upload result, not the delete.","triggerScenarios":"After the upload block, Files.delete(localSource.toPath()) throws IOException: file locked by another process, permission denied, or the file was concurrently removed by the JVM or an external cleaner.","commonSituations":"Workers with restricted tmpdir permissions, antivirus/agent processes holding the .hprof open, or small ephemeral disks filling up from repeated undeleted dumps.","solutions":["Ensure the worker process user has write/delete permission on the heap dump directory.","Free up disk space if repeated undeleted dumps are filling the disk; reduce heap dump frequency.","Manually delete stale heap_dump*.hprof files on workers if this recurs; upgrade Beam to pick up fixes in dump cleanup."],"exampleFix":"// ensure dump folder is writable by the harness user\nchmod 777 /tmp/heapdumps   // or run the worker with an appropriate UID","handlingStrategy":"try-catch","validationCode":"// pre-check writability of dump location\nif (!Files.isWritable(Paths.get(dumpFolder))) { /* relocate dump folder */ }","typeGuard":null,"tryCatchPattern":"try { Files.delete(localDump); } catch (IOException e) { LOG.warn(\"manual cleanup of {} needed: {}\", localDump, e.getMessage()); }","preventionTips":["Grant the worker user delete permissions on the dump directory","Avoid external agents that hold .hprof files open","Periodically clean stale heap dumps from worker volumes"],"tags":["java","apache-beam","heap-dump","filesystem"],"backgroundTag":"file-delete-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}