0

I'm Running Tomcat7 on a server (right now it's a virtual machine but should be configured as unlimited connexions).

I have connexions with a SMTP server and also with facebook Servers. My traffic is around 250hits/mins.

I'm running djabberd with around a few hundreds connected users average time.

Sometimes I get :

javax.mail.MessagingException: Could not connect to SMTP host: xxx.xxx.xxx.xxx, port: xxxxx;
  nested exception is:
    java.net.SocketException: No buffer space available
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
    at javax.mail.Service.connect(Service.java:295)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)
    at xxxxxxxxxxxxxxxx.controllers.EmailManager.sendEmail(EmailManager.java:151)

Or same error connecting to facebook servers.

netstat -n | wc -l 
348

Tomcat can accept acceptCount="1024" connexions.

Where should I investigate ?

[UPDATE 1]

Send an email :

Context envContext = (Context) initContext.lookup("java:/comp/env");
session = (javax.mail.Session) envContext.lookup("mail/emailSession");

MimeMessage message = new MimeMessage(session);
//....
Transport.send(message);

Configuration :

<resource-ref>
        <description>
            JNDI javamail session resource reference
        </description>
        <res-ref-name>mail/emailSession</res-ref-name>
        <res-type>javax.mail.Session</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

Facebook connexion :

FacebookClient facebookClient = new DefaultFacebookClient(accessToken);
User user = facebookClient.fetchObject("me", User.class);
Camille R
  • 1,433
  • 2
  • 17
  • 29
  • See this question http://stackoverflow.com/questions/1226155/hunt-down-java-net-socketexception-no-buffer-space-available – Michael Jun 11 '12 at 16:19
  • 1
    Note that the number of connections Tomcat can accept is irrelevant: you are failing to call *out* from your webapp, not seeing a client fail to call *in*. – Christopher Schultz Jun 11 '12 at 18:09
  • Cristopher Agreed, was just given as a configuration information. @Mikaveli, I've seen this question it is definitely interesting but didn't solve my problem. See the updates for the connections process. – Camille R Jun 12 '12 at 10:19

1 Answers1

2

What OS? Linux? You are probably hitting the limit on the max number of client sockets, there is no such thing as unlimited connections. Either somewhere in your app you aren't closing the connections or you just have too many open. "Too many" may be a lot lower than you think because it is limited by the max number of file descriptors a process can have open. If you are running Linux, take a look at http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/

Chase
  • 3,123
  • 1
  • 30
  • 35