Edge-Triggered epoll and starvation - Linux
This is a discussion on Edge-Triggered epoll and starvation - Linux ; Hello gurus!
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
buffer.
Otherwise next epoll_wait call may block forever ...
-
Edge-Triggered epoll and starvation
Hello gurus!
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
buffer.
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)
{
while(1)
{
int r = read(fd, buf, size);
if(r==-1)
{
if(errno == EINTR) continue;
if(errno == EAGAIN) break;
handle_read_error();
}
else
{
use_data(buf, r);
}
}
}
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
infinite.
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 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?
Yeah, but no sane person would write code like that.
> Have anyone seen something similar to this scenario in real life?
Only in code written by very inexperienced programmers. Experienced
programmers know that if you pick something up, you have to put it
down.
DS