问题描述
我已完成在Play框架中构建网站的工作.该网站部署在服务器上.但是,我面临着这样一个随机发生的问题.
I am completed building a website in Play framework. The website is deployed at server. But, I am facing some random occurring issue like this one..
This exception has been logged with id 6ilmmm0fk.
我之前也遇到过相同的错误.因此,我重新启动了完整的应用程序,但它不见了.但是,我再次面临着同样的错误.
I got the same error previously as well. So, I restarted the complete application and it was gone. But, again I am facing the same error.
为什么会发生此错误?
我得到了如下所示的堆栈跟踪
I got the stack trace that looks like this
play.api.Application$$anon$1: Execution exception[[SQLException: Timed out waiting for a free available connection.]]
at play.api.Application$class.handleError(Application.scala:293) ~[com.typesafe.play.play_2.10-2.2.2.jar:2.2.2]
at play.api.DefaultApplication.handleError(Application.scala:399) [com.typesafe.play.play_2.10-2.2.2.jar:2.2.2]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261) [com.typesafe.play.play_2.10-2.2.2.jar:2.2.2]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261) [com.typesafe.play.play_2.10-2.2.2.jar:2.2.2] at scala.Option.map(Option.scala:145) [org.scala-lang.scala-library-2.10.3.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2.applyOrElse(PlayDefaultUpstreamHandler.scala:261) [com.typesafe.play.play_2.10-2.2.2.jar:2.2.2]
Caused by: java.sql.SQLException: Timed out waiting for a free available connection.
at com.jolbox.bonecp.DefaultConnectionStrategy.getConnectionInternal(DefaultConnectionStrategy.java:88) ~[com.jolbox.bonecp-0.8.0.RELEASE.jar:na]
at com.jolbox.bonecp.AbstractConnectionStrategy.getConnection(AbstractConnectionStrategy.java:90) ~[com.jolbox.bonecp-0.8.0.RELEASE.jar:na]
at com.jolbox.bonecp.BoneCP.getConnection(BoneCP.java:553) ~[com.jolbox.bonecp-0.8.0.RELEASE.jar:na]
at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:131) ~[com.jolbox.bonecp-0.8.0.RELEASE.jar:na]
at play.api.db.DBApi$class.getConnection(DB.scala:67) ~[com.typesafe.play.play-jdbc_2.10-2.2.2.jar:2.2.2]
at play.api.db.BoneCPApi.getConnection(DB.scala:276) ~[com.typesafe.play.play-jdbc_2.10-2.2.2.jar:2.2.2][^[[31merror^[[0m] play - Cannot invoke the action, eventually got an error: java.sql.SQLException: Timed out waiting for a free available connection.
[^[[31merror^[[0m] application
堆栈跟踪显示Timed Out for SQL query
可能是我在数据库中打开的连接过多.
the stack trace shows Timed Out for SQL query
may be I am having too many open connections in database.
更新
我发现数据库正在泄漏连接.通过检查代码,我检查并更新了交易,如下所示
I have found that database is leaking connections. Going through the code I have checked and updated the transactions as follows
try{
Ebean.beginTransaction()
// All code goes here
//
Ebean.commitTransaction()
}catch{
e.printStackTrace();
}finally{
Ebean.endTransaction();
}
有没有更好的方法来识别打开的连接和漏洞.因为我仍然面临上述问题.
Is there a better way to identify open connections and loop holes. Because I am still facing the above issue.
更新
我已经迁移到 HikariCP JDBC,而不是Play框架BoneCP. BoneCP处理连接关闭的方式存在问题.
I have moved to HikariCP JDBC instead of Play frameworks BoneCP. There are issues with the way BoneCP handles connection closing.
推荐答案
您可能希望将jdbc池配置为在连接上具有更长的超时时间.在您的application.conf
中,您可以:db.default.connectionTimeout=30 seconds
You might want to configure your jdbc pool to have longer timeouts on your connections. In your application.conf
you could had: db.default.connectionTimeout=30 seconds
有关更多信息: http://www.playframework.com/documentation/2.2. x/SettingsJDBC
这篇关于Play Framework 2.2:错误:已使用ID记录此异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!