I have a thread responsible for polling various fds. I am using epoll_wait with timeout set. Following is the code snippet:
do {
n = epoll_wait(epollFd, eventsList, eventsTotal, timeoutMS);
}
while ((n<0) && (errno == EINTR));
eventsList memory contains timerfd, signalfd and socket fd.
The thread works well & handles timer event, socket open/read/write/close event & user-defined signal events.
But there are times when thread goes in infinite do-while loop as errno always returns EINTR.
Top -H of thread shows status as sleep. strace reveals it's calling
epoll_wait() in loop.
So what could go wrong as I am using well-accepted way of handling epoll_wait & EINTR? Could there be anything wrong with socket read/write/close that can cause above issue? Or with timerfd?
Update: strace -p output:
epoll_wait(8, {}, 8192, 10) = 0
epoll_wait(8, {}, 8192, 10) = 0
epoll_wait(8, {}, 8192, 10) = 0
epoll_wait(8, {}, 8192, 10) = 0
Then I took gcore and tried to get errno returned by epoll_wait(). It is 4 (EINTR)