std.socket Error: Too many open files.
Morgan McDermott
morganmcdermott at gmail.com
Sat Dec 9 15:08:31 PST 2006
Thomas Kuehne wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Morgan McDermott schrieb am 2006-12-09:
>> Hi all,
>> I've found a limitation in my current setup as far as sockets go; once
>> I've made about 500 transactions on different sockets between my test
>> client and test server, I receive the error "Error: Unable to create
>> socket. Too many open files." After I'm done with a socket I always shut
>> it down and close it.. I assume this is some sort of operating-system
>> specific limitation, but the explanation on std.socket.close (
>> "Immediately drop any connections and release socket resources" ) seems
>> to state that any file handles would be closed upon calling
>> Socket.close(). Is there a large delay between the close()'ing and the
>> release of resources, or am I overlooking something else simple and obvious?
>
> If you don't properly close the connection on both sides there are
> delays. Do you encounter the same issues if you use the following code?
>
> #
> # // casting due to http://d.puremagic.com/issues/show_bug.cgi?id=667
> # socket.shutdown(cast(SocketShutdown)2);
> #
> # socket.close();
> #
>
> instead of
>
> #
> # socket.close()
> #
>
> On Linux systems "netstat --tcp --numeric --programs --all" might help
> you to identify "ghost" sockets.
>
> Thomas
>
>
> -----BEGIN PGP SIGNATURE-----
>
> iD8DBQFFeq20LK5blCcjpWoRAgSNAJ91TRz0/vRLYmaSEo1W3/pMifVhDACghTwB
> flbtuQXL2aUKaSWelEgnni8=
> =buHL
> -----END PGP SIGNATURE-----
Thank you for the reply and the (highly) useful command! My code uses
the following to close sockets:
<code>
void close() {
writefln("Closing connection to %s",
thisSocket.remoteAddress());
//Shutdown both send and receive
std.socket.SocketShutdown how;
thisSocket.shutdown(how.BOTH);
thisSocket.close();
}
~this(){
this.close();
}
</code>
close() is called for all open sockets, and yet using your command, I
receive a long list of the connections that I just closed in the
TIME_WAIT state. According to
<http://www.port80software.com/200ok/archive/2004/12/07/205.aspx> this
isn't a problem with the software itself, but the mechanism TCP uses to
ensure that any packets destined for a socket have time to get to their
destination before a new socket gets bound on the same port.
Thanks again for the reply, Thomas.
~Morgan McDermott
More information about the Digitalmars-d-learn
mailing list