简体   繁体   English

java.net.SocketException:管道损坏

[英]java.net.SocketException: Broken pipe

I get this error or my jsp page every day: 我每天都会收到此错误或我的jsp页面:

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. 重新启动tomcat服务后,它工作正常。 (I use hibernate to connect to the mysql database) (我使用hibernate连接到mysql数据库)

I get this error or my JSP page every day (...) 我每天都会收到此错误或我的JSP页面(...)

I'm going to speculate a bit but if this happens every morning (ie 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 ). 我将推测一下,但如果每天早上都发生这种情况(即在一夜不活动之后),那么它可能与MySQL在8小时后默认关闭空闲连接( wait_timeout )有关。

If this is the case, either: 如果是这种情况,请:

  • configure tomcat to test connections on borrow using a validationQuery in the datasource configuration: 配置tomcat以使用数据源配置中的validationQuery测试借用连接:

     <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. 通过my.cnf/my.ini增加MySQL的wait_timeout ,或者通过连接命令行SQL客户端并输入SET GLOBAL wait_timeout=86400 ,或其他一些合适的秒数。

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. 我不知道第二个选项的所有后果,并没有真正推荐它,至少没有得到MySQL专家的更多反馈。

Looks like you (partially) loose the connection to your database. 看起来你(部分)松散了与数据库的连接。 MySQL tries to send something but the connection is lost. MySQL尝试发送一些东西,但连接丢失了。

Another mysql/tomcat user who reported a similiar problem, was adviced to use a connection pool, like c3p0 . 另一个报告类似问题的mysql / tomcat用户被建议使用连接池,如c3p0 The user replied that he wanted to use the Mysql/tomcat connection pooling first as described in mysqls reference manual . 用户回答说他想首先使用mysql / tomcat连接池,如mysqls参考手册中所述

This is original post (german language) . 这是原始帖子(德语)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM