@@ -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