[Help-gnutls] Re: Problems with unclosed file descriptors

Stefan D stefan at damp.homeip.net
Fri Mar 18 15:40:25 CET 2005


Thanks for your reply.

Simon Josefsson wrote:
> Stefan D <stefan at damp.homeip.net> writes:
> 
> 
>>Hi there
>>
>>I'm having some problems with an app I'm developing using gnutls 1.1.22. 
>>It works like a charm, but I'm getting some problems after the app has 
>>been running for a while. Then I get the "Too many open files" error. 
>>I've commented out everything other than the code for the ssl-socket, so 
>>it can't be any other socket/file causing it. The weird thing is that an 
>>"lsof | grep <appname>" shows a huge list with lines like:
>>
>><appname> 22554    stefan  351u  sock     0,0             7419429 can't 
>>identify protocol
>>
>>where "351u" goes from low values up to ~1000, and an "lsof | grep 
>><appname> | wc -l" jumps around a bit and the settles at 2075 every time 
>>and gets stuck there only returning "Too many open files" (which is 
>>after, not 2000 connections, but a lot). I was wondering if I'm doing 
>>anything wrong when I close the sockets. I've tried lots of different 
>>stuff, but nothing has worked so far. This is what I do:
>>---------------
>>if(useSSL && sessionInited) {
>>	gnutls_bye(session, GNUTLS_SHUT_WR);
>>	close(sockfd);
>>	gnutls_deinit(session);
>>	sessionInited = false;
>>}
>>---------------
>>
>>Is there anything I've forgotten? Any ideas? Really irritating problem 
>>because everything else works great, except that it stops working after 
>>a few hundred connections :)
> 
> 
> Maybe you need close(sockfd) when useSSL is false?  Assuming your
> application work both with/without SSL.  Just an idea.

That was just a typo when I removed some #ifdefs, close() is always called.

> I recall some issues with writing servers that accept many
> connections.  I am not sure if you are running into them, or if this
> is something simpler.  Perhaps you need to increase some OS limit.

Well, sorry for taking your time, but I solved it :) It was a small 
error that made the app open a socket and then overwrite the fd with the 
one from accept(). Ooops. Thanks anyway!

> Regards,
> Simon






More information about the Gnutls-help mailing list