Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

golang: cannot recover from Out Of Memory crash

Tags:

go

Under certain circumstances, calling append() triggers an out of memory panic and it seems append() itself doesn't return nil.

How could I avoid that panic scenario and show to my user "Resource temporary unavailable" ?

Best regards,

like image 785
vadmeste Avatar asked Jun 01 '15 15:06

vadmeste


1 Answers

You can't.

If the runtime can't allocate memory for append, it may not be able to recover, or communicate "Resource temporary unavailable" to the user. For example, GC might need to allocate to clean up, or the scheduler might be trying to allocate a new thread. Because there's no way to strictly control allocations in a Go program, there's no way to gracefully handle running out of memory.

All OOM conditions terminate a Go program.

like image 74
JimB Avatar answered Nov 11 '22 17:11

JimB