skip to content

As the lead for a fleet of JVM services in containers, what crash evidence do you make every JVM keep, and do you enable core dumps in production?

level: principalimportance: nice to knowfreq 25%

answer

  1. the cheap evidence is always on
  2. ErrorFile on a volume, %p
  3. core size close to resident memory
  4. ulimit -c and core_pattern
  5. secrets in a core, retention

basics

~20 s

Always keep the hs_err log: -XX:ErrorFile with %p on a persistent volume, or ErrorFileToStdout into central logs. Core dumps are costly and hold memory contents, so enable them per service where native crashes recur, with storage, access and retention decided first.

solid answer

~50 s

The fatal error log is cheap and written only on a crash, so every JVM keeps it: `-XX:ErrorFile=/crash/hs_err_pid%p.log` on a volume that outlives the container, or `-XX:+ErrorFileToStdout` so the report reaches the log pipeline, plus the exit code in the orchestrator's records. Core dumps are a real tradeoff. HotSpot requests one by default (`CreateCoredumpOnCrash` is true), but whether one is written depends on the core size limit (`ulimit -c`) and on the kernel's `core_pattern`, which is set for the whole host, not per container. A core is roughly the process's resident memory, heap included, so it costs disk, time and network, and it contains whatever was in memory: tokens, passwords, user data. My default is crash logs everywhere and cores off, then cores on for a service whose crash logs alone have not named a cause, written to restricted storage with short retention.

go deeper

for a junior

Recall that a crash can leave an hs_err log and a core dump, and that the log is the small, always useful one.

for a middle

Know the options that place the log (ErrorFile, ErrorFileToStdout) and the three things a core needs: CreateCoredumpOnCrash, a non-zero ulimit -c and a usable core_pattern.

for a senior

Explain what a core adds over the log for memory corruption, and why its size and contents make it expensive to produce and handle.

for a principal

Own the fleet default and its exceptions: logs always, cores on evidence, storage and access rules for cores, and a staged crash test that proves the policy.

## Two kinds of crash evidence When a JVM crashes there is no live process left to attach a tool to, so the decision about what evidence exists has to be taken before the crash. HotSpot can leave two artefacts: - the **fatal error log** (`hs_err_pid<pid>.log`), a text report, typically tens to a few hundred kilobytes: the signal, the problematic frame, the crashing thread's stacks, the VM state, the non-default flags, the memory map and selected environment variables; - a **core dump**, an image of the process's memory at the moment it died, which a debugger or the JDK's serviceability tools can open together with the exact `java` binary that produced it. The first is nearly free. The second can be the only way to find out which object or buffer was damaged, and it is expensive in several ways. ## The always-on part Every production JVM should keep the crash log where someone will find it. In a container the default location, the working directory, usually lives in the container's writable layer and disappears with it. The options, from the JDK 25 source: | Option | What it does | Fits when | |---|---|---| | `-XX:ErrorFile=/crash/hs_err_pid%p.log` | writes the log to that path, `%p` expanded to the pid | a persistent volume is mounted | | `-XX:+ErrorFileToStdout` | prints the full report to stdout instead of a file | logs are collected from stdout | | `-XX:OnError="<command>"` | runs commands after the report is written, `%p` expanded | a hook should copy or announce the file | | `-XX:ErrorLogTimeout` | limits the time spent writing the report (120 s by default) | a hung error handler must not delay a restart | Keep `%p` in any file name so a second crash does not overwrite the first, and record each death's exit code next to it. A standard JVM launch template across the fleet makes this a decision taken once. ## What a core dump costs HotSpot asks for a core by default: `CreateCoredumpOnCrash` is `true` in JDK 25, and the crash log's header says either `Core dump will be written` or `No core dump will be written` with the reason. Whether a file actually appears is decided by the operating system: - the **core size limit** (`ulimit -c`, the process's `RLIMIT_CORE`) must allow it; it is often 0 in images and service units; - the kernel's **`/proc/sys/kernel/core_pattern`** decides the file name or pipes the core to a handler program. It is a host-wide kernel setting, so in containers the platform team owns it, not the service; - there must be room: a core is roughly the size of the process's resident memory, so a JVM with an 8 GB heap can produce a core of several gigabytes, written while the orchestrator waits to restart it. The largest cost is not disk. A core holds everything the process had in memory: session tokens, database passwords, decrypted payloads, users' personal data. It must be treated like a production database backup: restricted access, encrypted storage, a short retention period and a record of who opened it. ## The decision There is no single right setting; a reasonable fleet policy looks like this: 1. **Crash logs always**, to a persistent location or the log pipeline, with exit codes recorded. 2. **Cores off by default**, because most crashes are diagnosed from the log (a native library frame, a compiler thread, a known JDK bug) and the cost and the data exposure are real. 3. **Cores on, per service, on evidence**: when the same service keeps crashing and its logs point at memory corruption or a frame nobody can explain, enable them for that service, with the storage and access rules above in place first. 4. **A path to the vendor**: a crash log, the core and the exact JDK build are what a JDK or library maintainer needs, so keep the binary that produced the core available. The tradeoffs to weigh openly are diagnosability against memory exposure, restart time against evidence (a large core delays the restart), and a fleet-wide default against per-service exceptions. Whatever is chosen, test it: crash a staging JVM on purpose and confirm the log, and the core if enabled, arrive where the policy says.

  • Why can a service team not simply turn core dumps on from inside its own container image?
    Because the kernel's `core_pattern`, which decides where cores go or which program receives them, is one host-wide setting that a container shares with the host. The team can raise its own core size limit if the runtime allows it, but where the core lands, and whether a host handler collects it, is the platform team's decision.
  • How do you check that the crash-evidence policy works before a real crash tests it?
    Crash a staging JVM deliberately with the production launch template, then confirm that the crash log reached the volume or the log pipeline, that the exit code was recorded, and, where cores are enabled, that the core arrived in the restricted store and opens with the matching JDK build.

  • Leaves the hs_err file in the container's working directory.
  • Assumes CreateCoredumpOnCrash alone guarantees a core file is written.
  • Enables core dumps fleet-wide with no access control or retention.
  • Forgets that a core holds secrets and personal data from memory.
  • Treats core_pattern as a per-container setting the service controls.