java.net.BindException: Cannot assign requested address, java.io.IOException: Too many open files

时间:2015-07-28 22:56:40

标签: java oracle network-programming

I am getting exception java.net.BindException: Cannot assign requested address, and if this exception occurred I try to bind it again with the same port and host. But after some attempt of bind I am getting java.io.IOException: Too many open files.

Stack Trace:

    java.net.BindException: Cannot assign requested address
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:444)
    at sun.nio.ch.Net.bind(Net.java:436)
    at sun.nio.ch.SctpServerChannelImpl.bind(SctpServerChannelImpl.java:109)
    at com.sun.nio.sctp.SctpServerChannel.bind(SctpServerChannel.java:184).

and after some failure:

    java.io.IOException: Too many open files
    at sun.nio.ch.IOUtil.makePipe(Native Method)
    at sun.nio.ch.EPollSelectorImpl.<init>(EPollSelectorImpl.java:65)
    at sun.nio.ch.EPollSelectorProvider.openSelector(EPollSelectorProvider.java:36)
    at java.nio.channels.Selector.open(Selector.java:227)

Is it possible that FD remains open when java.net.BindException: Cannot assign requested address ?

3 个答案:

答案 0 :(得分:0)

This is usually an OS level issue. Look into bumping up the number of files that can be open. On linux the setting is in /etc/security/limits.conf:

UID soft nofile 4096 UID hard nofile 10240

答案 1 :(得分:0)

Is it possible that FD remains open when java.net.BindException: Cannot assign requested add?

Yes. You have to close the socket yourself. Clearly you have a socket leak.

I don't see the point of retrying the bind. It will still fail. Probably the original bind problem is also due to a socket leak.

答案 2 :(得分:0)

也许ip问题到了/ etc / hosts并将其改为