Golang: cannot recover from memory failure

In certain circumstances, calling append () causes a panic from memory and it seems that append () itself does not return nil.

How could I avoid this panic scenario and show my user "The resource is temporarily unavailable"?

Yours faithfully,

+6
source share
1 answer

You can not.

If the runtime cannot allocate memory for adding, it may be impossible to restore or to contact the user "Resource is temporarily unavailable." For example, the GC may need to be allocated for cleaning, or the scheduler may try to allocate a new thread. Since there is no way to strictly control allocations in a Go program, there is no way to gracefully manage memory exhaustion.

All OOM conditions complete the Go program.

+6
source

Source: https://habr.com/ru/post/988326/


All Articles