vishvananda / netlink

Simple netlink library for go.
Apache License 2.0
2.87k stars 748 forks source link

high cpu usage after 916f9685fa42fc711f76a7f48d058e2656f7edf6 which changed Subscribe to nonblocking mode #959

Open fortitudepub opened 8 months ago

fortitudepub commented 8 months ago

in the following code snippets

        for {
            msgs, from, err := s.Receive()
            if err != nil {
                if err == syscall.EAGAIN {
                    continue
                }
                if cberr != nil {
                    cberr(fmt.Errorf("Receive failed: %v",
                        err))

if the socket baking s is changed to non blocking mode as the commit 916f9685fa42fc711f76a7f48d058e2656f7edf6 did, when there is no event in the socket, kernel will always return EAGAIN which cause the goroutine to a busy loop.

fasaxc commented 4 months ago

Looks like the bad commit was reverted here 1e68b2710dc35a6ac34bcd7f27a70a0655d7a45d