{"record":{"id":"9eb7428e82881673","repo":"apache/beam","slug":"unable-to-dump-heap","errorCode":null,"errorMessage":"Unable to dump heap: ","messagePattern":"Unable to dump heap: ","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sdks/java/harness/src/main/java/org/apache/beam/fn/harness/status/MemoryMonitor.java","lineNumber":498,"sourceCode":"   * Dumps the heap to a file and return the name of the file, or {@literal null} if the heap should\n   * not or could not be dumped.\n   *\n   * @return The name of the file the heap was dumped to, otherwise {@literal null}.\n   */\n  public @Nullable File tryToDumpHeap() {\n    if (!canDumpHeap) {\n      return null;\n    }\n\n    // Clearing this list should \"release\" some memory that will be needed to dump the heap.\n    // We could try to reallocate it again if we later notice memory pressure has subsided,\n    // but that is risk. Further, leaving this released may help with the memory pressure.\n    reservedForDumpingHeap = null;\n\n    try {\n      return dumpHeap();\n    } catch (Exception e) {\n      LOG.warn(\"Unable to dump heap: \", e);\n      return null;\n    }\n  }\n\n  @SuppressFBWarnings(\"DM_EXIT\") // we deliberately System.exit under memory\n  private void shutDownDueToGcThrashing(int thrashingCount) {\n    File heapDumpFile = tryToDumpHeap();\n    LOG.error(\n        \"Shutting down JVM after {} consecutive periods of measured GC thrashing. \"\n            + \"Memory is {}. Heap dump {}.\",\n        thrashingCount,\n        describeMemory(),\n        heapDumpFile == null ? \"not written\" : (\"written to '\" + heapDumpFile + \"'\"));\n\n    System.exit(1);\n  }\n\n  /** Runs this thread. */","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/status/MemoryMonitor.java#L480-L516","documentation":"MemoryMonitor.tryToDumpHeap logs this warning when dumpHeap() throws any Exception while attempting to write a .hprof heap dump (after releasing the memory reserved for dumping). The method returns null, so no dump is produced; the message is appended to the wrapped cause. This means an OOM diagnosis will lack a heap dump.","triggerScenarios":"The HotSpotDiagnosticMXBean / dumpHeap call fails under severe memory pressure: not enough free disk for the dump, dump target not writable, unsupported JVM flags, or OOM while writing the dump itself.","commonSituations":"Containers with small or read-only filesystems attempting to dump multi-GB heaps; JVMs started with HeapDumpOnOutOfMemoryError interfering; restricted security managers or non-HotSpot JVMs.","solutions":["Ensure the dump target directory has free disk space at least as large as the heap and is writable by the worker.","Check the wrapped cause in the log for the exact failure and fix accordingly (disk full, permission, unsupported option).","If disk is the constraint, configure a smaller heap, or reserve dump space by tuning MemoryMonitor's reservation.","Verify the worker runs on a HotSpot-based JDK that supports the dumpHeap diagnostic command."],"exampleFix":"// before: read-only or tiny volume\n--heapDumpFolder=/mnt/ro-volume\n// after: writable volume with headroom\n--heapDumpFolder=/tmp/heapdumps","handlingStrategy":"validation","validationCode":"// verify dump target viability before relying on dumping\nFile dumpDir = new File(dumpFolder);\nlong heapBytes = Runtime.getRuntime().maxMemory();\nif (dumpDir.getUsableSpace() < heapBytes) throw new IllegalStateException(\"insufficient disk for heap dump in \" + dumpFolder);","typeGuard":null,"tryCatchPattern":"try { monitor.tryToDumpHeap(); } catch (Throwable t) { LOG.warn(\"dump attempt failed entirely\", t); }","preventionTips":["Provision disk space comparable to max heap in the dump folder's volume","Use a HotSpot JDK in worker images","Check the wrapped cause in logs to target the specific failure (disk, permissions, JVM support)"],"tags":["java","apache-beam","heap-dump","jvm","oom"],"backgroundTag":"heap-dump-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"}