Java.net.SocketException: Unable to allocate memory (not Mac)

I have a java application deployed on tomcat 7 running on ubuntu 10.04. While opening the server socket, there was a problem that I could not reproduce so far:

java.net.SocketException: Cannot allocate memory at java.net.PlainSocketImpl.socketBind(Native Method) at java.net.AbstractPlainSocketImpl.bind(Unknown Source) at java.net.ServerSocket.bind(Unknown Source) at org.subethamail.smtp.server.SMTPServer.createServerSocket(SMTPServer.java:338) at org.subethamail.smtp.server.SMTPServer.start(SMTPServer.java:291) 

All I was able to figure out is that this happens in some specific version of MacOS that doesn't matter to me, and also in OpenJDK that doesn't matter either (I'm using Oracle JRE 1.7.0_17). Another the possible reason is the virtualization environment, but in my case it happens in the hardware window.

So the question is, has anyone ever encountered the same problem and what might be a possible solution.

Update There was this thing: tomcat consumed almost the entire heap, approximately 700 mb, it was caused by a memory leak in my code. But, as I understand it, the exception speaks of a socket buffer at the system level, so it seems to be unconnected with a bunch of java. However, this is the only explanation that I have received so far, and it is very illusory, in my opinion.

Update 2 In the end, we were able to reproduce the problem several times, so it was not a memory leak. I considered authbind as a possible source of the problem when I first encountered it, but, unfortunately, I did not pay much attention to this. When I had another hardware kernel affected by this problem, I tried to bind an untethered port and succeeded, while trying to bind privileged ports threw exceptions. So in the end I replaced authbind iptables.

Basically, fady taher answers with authbind points, but Danny Thomas's answer gives very interesting information about the connections between the forward and "Unable to allocate memory", in fact we also use the process builder to run bash scripts, so there is a high probability that the problem may be caused by him.

+7
java tomcat ubuntu
source share
5 answers

It seems that you do not have enough physical memory or a swap - on the affected systems, check the memory and exchange.

Whether your application is running to execute external commands, fork / exec can contribute. You might consider letting the memory recompile if in this case:

http://bryanmarty.com/blog/2012/01/14/forking-jvm/

+4
source share

Also check the following points:

  • Run a memory test to fix bad memory blocks.
  • Run a disk check on the swap partition (equivalent to Mac OS)
  • Check user resource limits ( ulimit )
+1
source share

dunno if that helps but check

Memory error while trying to change Apache Tomcat port from 8080 to 80

0
source share
  • You can extend the Java heap space check.
  • If the project you are developing was created by another version of Java, this problem may occur.
0
source share

Try reducing the memory allocated by Tomcat (the -Xmx option in the catalina.sh file). Also increase the maximum tomcat heap size. If this does not solve the problem, you need to find a memory leak in your code, one of such java melody tools, use it and find a memory leak in to solve the problem.

0
source share

All Articles