This can be prevented using earlyoom (which is packaged in most distros):
https://github.com/rfjakob/earlyoom
It's probably too difficult to fix the underlying design errors, e.g. fork() duplicating the process's entire address space, thus requiring overcommit and copy-on-write, but losing only one process beats losing all of them. earlyoom should be enabled by default.