Tuesday, April 12, 2011

Socket Accept Failed

Encountered funny error thrown by JBoss today when deploying JBoss 4.2.3GA

[JIoEndpoint] Socket accept failed
java.net.SocketException: Too many open files

Apparently JBoss somehow opened too many socket for some reason and start complaining itself.

So I've learned another new handy command to see what file handle are open using the following command.

lsof -p [PID]

Note: PID = process id, use ps command to see the process id.

If you want to count how many were open, can add wc command to it.

lsof -p [PID] | wc

Example output:

[root@localhost]# lsof -p 30328 | wc
1239 11141 153600

Translation: 1239 lines, 11141 words, 153600 chars.

So to solve this issue, go to jboss/server/default/deploy/jboss-web.deployer/ folder (might not be the exact path, depends on your JBoss version) and open server.xml file, replace the following

<Connector port="8080" address="${jboss.bind.address}"
maxThreads="250" maxHttpHeaderSize="8192"
emptySessionPath="true" protocol="HTTP/1.1"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />

with

<Executor name="appThreadpool" namePrefix="activeThread-"
maxThreads="150" minSpareThreads="3" maxIdleTime="30000" />

<Connector executor="appThreadpool" port="8080"
address="${jboss.bind.address}" maxThreads="150"
maxHttpHeaderSize="8192" minSpareThreads="3"
maxSpareThreads="20" emptySessionPath="true" protocol="HTTP/1.1"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />

And then replace the following

<Connector port="8009" address="${jboss.bind.address}" protocol="AJP/1.3"
emptySessionPath="true" enableLookups="false" redirectPort="8443" />

with

<Connector executor="appThreadpool" port="8009"
address="${jboss.bind.address}" protocol="AJP/1.3"
emptySessionPath="true" enableLookups="false" redirectPort="8443" />


Then save the server.xml and restart your JBoss.