Help! help! rocky9.5 system is stuck

package main

import (
        "fmt"
        "os"
        "os/signal"
        "runtime"
        "syscall"
        "time"
)

var holder = make([][]byte, 0)

func main() {

        blockSize := 100 * 1024 * 1024
        printInterval := time.Second

        sigChan := make(chan os.Signal, 1)
        signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)

        ticker := time.NewTicker(printInterval)
        defer ticker.Stop()

        var totalAllocated uint64

        for {
                select {
                case <-ticker.C:
                        var m runtime.MemStats
                        runtime.ReadMemStats(&m)
                        fmt.Printf("Allocated: %.2f GB\n", float64(totalAllocated)/1024/1024/1024)

                case sig := <-sigChan:
                        fmt.Printf("Received signal: %v\n", sig)
                        return

                default:
                        buf := make([]byte, blockSize)
                        time.Sleep(100 * time.Second)
                        for i := range buf {
                                buf[i] = byte(i % 256)
                        }
                        holder = append(holder, buf)
                        totalAllocated += uint64(blockSize)
                }
        }
}

I executed a piece of go code, constantly applying for memory, memory ran out, the system was stuck, the process was not killed。
I have tried programming languages such as php, node.js, python, and java. When memory runs out, rocky9.5 may freeze. So what should I do? In the go code, I applied for memory and deliberately slept for 100 seconds, but still got stuck in the end。

This link is the topic I posted before.

If you ran out of memory, then you need more memory. Either that or something is wrong with your code.

hi,iwalker
What I mean is that when my memory is exhausted, the system should kill my process instead of causing the entire system to freeze。

Ah, I’m guessing then it’s a continuation of this thread: Rockylinux9 is stuck - #19 by jlehtone

Yeah I remember this convo now.

Yes, I haven’t found a suitable solution yet. I’ve noticed that as long as the memory is exhausted, it might freeze, but I hope to be killed when entering the system

Then you probably need to effectively disable overcommit with:

vm.overcommit_memory = 2

when it’s set to zero which is the default, then your system is behaving exactly how it should do. OOM killer will kill the process. That doesn’t mean it will happen when you expect it to, the system will do it. If that takes 10 minutes or longer, then that is how it is.

From what I remember though you didn’t want to change that value, so I expect you’ll not get a solution to your problem.

Did you try disabling swap?

I’ve seen this problem before on el9 when available memory and swap is short - one workaround when this happens (if you have shell access as root) is to create/add an extra swapfile - this usually gives enough breathing space to allow things to calm down