简体   繁体   English

Dropwizard应用程序中的管道破损异常

[英]Broken Pipe exception in Dropwizard application

I am getting a 'broken pipe' exception when the server is left running for a long time without any http requests. 当服务器长时间运行而没有任何http请求时,出现“管道中断”异常。 Upon some investigation I found that this exception occures because the server closes its database connection and occurs when a client requests resources when the connection is close. 经过一番调查,我发现发生此异常是因为服务器关闭了其数据库连接,并在连接关闭时客户端请求资源时发生了。 To fix this I added the following to the jdbc conenction url 为了解决这个问题,我将以下内容添加到了jdbc连接网址中

?autoReconnect=true

I also upped the heap memory on the machine just in case. 我还增加了机器上的堆内存,以防万一。 Also there are not many http clients requesting resources from this dropwizard server. 同样,没有很多http客户端从此dropwizard服务器请求资源。 Is there anything else that might be going on? 还有其他可能发生的事情吗?

The error message for reference 错误信息供参考

You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

I there a way to configure connection pool in dropwizard application? 我有办法在dropwizard应用程序中配置连接池吗? Or is it a good practice to change the 'interactive-timeout' and 'wait_timeout'property of mysqld to be more than 8 hours ? 还是将mysqld的“ interactive-timeout”和“ wait_timeout”属性更改为8小时以上是一种好习惯?

Thanks for the help , I fixed this issue by adding the following to the yaml file 感谢您的帮助,我通过将以下内容添加到yaml文件中解决了此问题

  1. checkConnectionWhileIdle : true checkConnectionWhileIdletrue
  2. checkConnectionOnReturn : true checkConnectionOnReturntrue
  3. checkConnectionOnBorrow : true checkConnectionOnBorrowtrue

And making sure all transactions are committed, rolled back in case of exceptions and sessions are closed after use. 并确保所有事务都已提交,在发生异常的情况下回滚,并在使用后关闭会话。

Depending on whether you are using JDBi , Hibernate or something else, I recommend using the bundles provided to set up connectivity. 根据您使用的是JDBiHibernate还是其他工具,我建议使用提供的捆绑软件来建立连接。 Those bundles come with a built-in pool that's easily configurable as the examples on the links should show. 这些捆绑包带有一个内置池,可以很容易地对其进行配置,如链接上的示例所示。

If you use plain JDBC or another OR mapper, you can always write a Managed Object or a proper bundle yourself, or try to leverage a ManagedPooledDatasource directly during startup. 如果您使用纯JDBC或其他OR映射器,则始终可以自己编写托管对象或适当的捆绑包,或者尝试在启动过程中直接利用ManagedPooledDatasource

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

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