From 4d5cb076e25342e5e5bc03382377999f348b5a95 Mon Sep 17 00:00:00 2001 From: Vitaly Terentyev Date: Thu, 21 May 2026 16:02:09 +0400 Subject: [PATCH] [Cherrypick] Configure JVM so that it exits upon OutOfMemoryError originating in JVM (#38567) --- sdks/java/container/boot.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/sdks/java/container/boot.go b/sdks/java/container/boot.go index 3ce79e4927eb..ad29f8d940ac 100644 --- a/sdks/java/container/boot.go +++ b/sdks/java/container/boot.go @@ -195,9 +195,6 @@ func main() { "-XX:+UseParallelGC", "-XX:+AlwaysActAsServerClassMachine", "-XX:-OmitStackTraceInFastThrow", - // Crash and restart instead of throwing OutOfMemoryError which may be caught by user or - // framework code and leave things in a degraded state. - "-XX:+ExitOnOutOfMemoryError", } enableGoogleCloudProfiler := strings.Contains(options, enableGoogleCloudProfilerOption) @@ -227,18 +224,16 @@ func main() { args = append(args, jammAgentArgs) } - enableHeapDumpsOnOom := false // If heap dumping is enabled, configure the JVM to dump it on oom events. if pipelineOptions, ok := info.GetPipelineOptions().GetFields()["options"]; ok { if heapDumpOption, ok := pipelineOptions.GetStructValue().GetFields()["enableHeapDumps"]; ok { - enableHeapDumpsOnOom = heapDumpOption.GetBoolValue() + if heapDumpOption.GetBoolValue() { + args = append(args, "-XX:+HeapDumpOnOutOfMemoryError", + "-Dbeam.fn.heap_dump_dir="+filepath.Join(dir, "heapdumps"), + "-XX:HeapDumpPath="+filepath.Join(dir, "heapdumps", "heap_dump.hprof")) + } } } - if enableHeapDumpsOnOom { - args = append(args, "-XX:+HeapDumpOnOutOfMemoryError", - "-Dbeam.fn.heap_dump_dir="+filepath.Join(dir, "heapdumps"), - "-XX:HeapDumpPath="+filepath.Join(dir, "heapdumps", "heap_dump.hprof")) - } // Apply meta options const metaDir = "/opt/apache/beam/options"