Edge-Triggered epoll and starvation
I have a question about epoll and possible starvation.
As epoll(4) says, when epoll is used in Edge-Triggered mode
it's very important to read all the data available in the
Otherwise next epoll_wait call may block forever (if there
are no changes on monitored file descriptor).
Lets suppose, that epoll_wait detected new events on three
file descriptors 5, 6 and 7.
So, we should handle I/O on all of them.
Read handling loop may be implemented as follows:
void handle_read_event(int fd)
int r = read(fd, buf, size);
if(errno == EINTR) continue;
if(errno == EAGAIN) break;
We are reading as much data as possible (since epoll-ET is used).
Lets now suppose that peer is much more faster and we are unable
to read data at the same rate (fast producer, slow consumer).
In such a case the loop presented above may be potentially
So, this leads to starvation and DoS.
Really, we are unable to handle new events as well as I/O on already
ready descriptors (6 and 7 in the example).
Are my conclusions correct?
Have anyone seen something similar to this scenario in real life?
Thank you beforehand!
Re: Edge-Triggered epoll and starvation
On May 30, 4:26*pm, Krivenok Dmitry <krivenok.dmi...@gmail.com> wrote:
> So, this leads to starvation and DoS.
> Really, we are unable to handle new events as well as I/O on already
> ready descriptors (6 and 7 in the example).
> Are my conclusions correct?[/color]
Yeah, but no sane person would write code like that.
> Have anyone seen something similar to this scenario in real life?[/color]
Only in code written by very inexperienced programmers. Experienced
programmers know that if you pick something up, you have to put it