When I use ZMQ to receive messages over TCP on mac, I got the program using 100% of CPU after some hours. By using lsof, I found kqueue got into a wired state
myprogram 56486 user 13u KQUEUE count=4, state=0x8
and the grogram keeps waiting on something.
Can someone tell me what does state 8 mean in queue?
codes details:
language: Golang
package: github.com/pebbe/zmq4
poller := zmq.NewPoller()
// sub is the zmq socket over TCP that receives message
poller.Add(sub, zmq.POLLIN)
for {
polled, _ := poller.Poll(zeroMQTimeout)
if len(polled) >= 1 && polled[0].Events&zmq.POLLIN != 0 {
msg, _ := sub.RecvMessageBytes(0)
go handleMsg(msg[1])
} else {
fmt.Printf("something happened at %s\n", time.Now())
}
}
by loging, I see that the main goroutine hangs somewhere in the for loop, and it is likely to be at sub.RecvMessageBytes
.
Using a blocking receive instead of a poller does not improve the situation.