lkml.org 
[lkml]   [2008]   [Nov]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: epoll behaviour after running out of descriptors
Olaf van der Spek a écrit :
> On Sun, Nov 2, 2008 at 7:48 PM, Davide Libenzi <davidel@xmailserver.org> 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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2008-11-02 20:13    [W:0.225 / U:0.424 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site