Re: epoll behaviour after running out of descriptors
From: Eric Dumazet
Date: Sun Nov 02 2008 - 14:10:55 EST
Olaf van der Spek a Ãcrit :
On Sun, Nov 2, 2008 at 7:48 PM, Davide Libenzi <davidel@xxxxxxxxxxxxxxx> wrote:
Why don't you grep for TIME_WAIT?
Because I don't have access to the test environment at the moment.
Hello Olaf
If your application calls accept() and accept() returns EMFILE, its a nullop.
On listen queue, socket is still ready for an accept().
Since you use edge trigered epoll, you'll only reveive new notification.
You probably had in you app a : listen(sock, 10), so after 10 notifications,
your listen queue is full and TCP stack refuses to handle new connections.
In order to cope with this kind of thing the trick I personnally use is to always keep
around a *free* fd, that is :
At start of program, reserve an "emergency fd"
free_fd = open("/dev/null", O_RDONLY)
Then later :
newfd = accept(...)
if (newfd == -1 && errno == EMFILE) {
/* emergency action : clean listen queue */
close(free_fd);
newfd = accept(...);
close(newfd); /* forget this incoming connection, we dont have enough fd */
free_fd = open("/dev/null"; O_RDONLY);
}
Of course, if your application is multi-threaded, you might adapt (and eventually reserve
one emergency fd per thread)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/