Skip to content

Commit 37ae1ff

Browse files
authored
[Java Portable SDK] Configure JVM so that it exits upon OutOfMemoryError originating in JVM. (#37764)
1 parent c68f520 commit 37ae1ff

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

sdks/java/container/boot.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ func main() {
192192
"-XX:+UseParallelGC",
193193
"-XX:+AlwaysActAsServerClassMachine",
194194
"-XX:-OmitStackTraceInFastThrow",
195+
// Crash and restart instead of throwing OutOfMemoryError which may be caught by user or
196+
// framework code and leave things in a degraded state.
197+
"-XX:+ExitOnOutOfMemoryError",
195198
}
196199

197200
enableGoogleCloudProfiler := strings.Contains(options, enableGoogleCloudProfilerOption)
@@ -221,16 +224,18 @@ func main() {
221224
args = append(args, jammAgentArgs)
222225
}
223226

227+
enableHeapDumpsOnOom := false
224228
// If heap dumping is enabled, configure the JVM to dump it on oom events.
225229
if pipelineOptions, ok := info.GetPipelineOptions().GetFields()["options"]; ok {
226230
if heapDumpOption, ok := pipelineOptions.GetStructValue().GetFields()["enableHeapDumps"]; ok {
227-
if heapDumpOption.GetBoolValue() {
228-
args = append(args, "-XX:+HeapDumpOnOutOfMemoryError",
229-
"-Dbeam.fn.heap_dump_dir="+filepath.Join(dir, "heapdumps"),
230-
"-XX:HeapDumpPath="+filepath.Join(dir, "heapdumps", "heap_dump.hprof"))
231-
}
231+
enableHeapDumpsOnOom = heapDumpOption.GetBoolValue()
232232
}
233233
}
234+
if enableHeapDumpsOnOom {
235+
args = append(args, "-XX:+HeapDumpOnOutOfMemoryError",
236+
"-Dbeam.fn.heap_dump_dir="+filepath.Join(dir, "heapdumps"),
237+
"-XX:HeapDumpPath="+filepath.Join(dir, "heapdumps", "heap_dump.hprof"))
238+
}
234239

235240
// Apply meta options
236241
const metaDir = "/opt/apache/beam/options"

0 commit comments

Comments
 (0)