grails – How to resolve the error java.net.SocketException: Too many open files

grails – How to resolve the error java.net.SocketException: Too many open files

You have certainly open the maximum number of open file/sockets. The maximum number of open files or sockets on Linux machines is 1024. by default. You need to change that. You can refer this java.net.SocketException Too many open files

You can use below query to check from your terminal to get maximum number of allowed open files

ulimit -n 

From here:

Whats happening is that the underlying sockets arent being closed,
and eventually the JVM bumps into the systems per-process limit on
open file descriptors.

The right solution would be to make the sockets close at the Right
Time (which I guess is when, or shortly after, the server has closed
its end of the connection). That seems hard with HttpURLConnection.
Its all very confused:

  • disconnect() just seems to close it immediately — or not;
    the Javadocs are intentionally vague about what it actually
    does, and especially when it does it.

  • close() might be the right choice. The Evaluation section of
    Java bug #4147525 says: … call close() on the input and/or
    output stream. This will correctly result in the underlying
    socket being closed when you arent doing keepalive
    connections and will correctly cache and reuse keepalive
    connections (and which will timeout and close themselves
    after a short time anyway).

  • But maybe not. Bug #4142971 says: Calling the close()
    methods has no effect one way or the other on whether the
    underlying HTTP connection is persistent.

Failing a clear answer, perhaps the HttpURLConnection objects could be
added to a list, and all disconnected at once at the end of the test
run. Thatd still limit the total size of the run, but at least the
lost descriptors wouldnt accumulate between runs.

Maybe the real answer is to give up on HttpURLConnection, and instead
use the HTTP Client from Jakarta Commons. Someone suggested that in
connection with a different problem (bug
#4143518).

java.net.SocketException: Too many files opencan be seen any Java Server application e.g. Tomcat, Weblogic, WebSphere etc, with client connecting and disconnecting frequently.

You can find out how to solve java.net.SocketException: Too many files open here

grails – How to resolve the error java.net.SocketException: Too many open files

Leave a Reply

Your email address will not be published.