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

Simon Josefsson jas at extundo.com
Fri Mar 18 13:28:10 CET 2005

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.

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.


More information about the Gnutls-help mailing list