Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.net.SocketException: Broken pipe

I get this error or my jsp page every day:

java.net.SocketException

MESSAGE: Broken pipe

STACKTRACE:

java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2637)
        ....

After restarting the tomcat service it works fine. (I use hibernate to connect to the mysql database)

like image 705
Benni Avatar asked Jul 22 '10 06:07

Benni


1 Answers

I get this error or my JSP page every day (...)

I'm going to speculate a bit but if this happens every morning (i.e. after a night of inactivity), then it might be related to the fact that MySQL closes idle connections after 8 hours by default (the wait_timeout).

If this is the case, either:

  • configure tomcat to test connections on borrow using a validationQuery in the datasource configuration:

    <parameter>
      <name>validationQuery</name>
      <value>select 1</value>
    </parameter>
    
  • increase MySQL's wait_timeout via my.cnf/my.ini, or by connecting with a command-line SQL client and entering SET GLOBAL wait_timeout=86400, or some other suitable number of seconds.

I'm not aware of all the consequences of the second option and don't really recommend it, at least not without getting more feedback from MySQL experts.

like image 125
Pascal Thivent Avatar answered Sep 30 '22 05:09

Pascal Thivent