所以在最近几天我一直受到这个问题的困扰,我不确定是什么导致它或从哪里开始寻找。我正在使用docker容器(T2.Small)+ RDS(T2.micro)在Amazon Beanstalk上运行Play 2.4.1,Anorm 2.5,MySql 5.6。在向服务器发出API请求时,我遇到了间歇性问题。我的日志文件已满,错误如下。它抱怨与数据库的连接超时但如果我检查RDS它仍然显示所有连接活动。如果我远程进入MySql服务器并运行SHOW processlist
我看到所有连接,他们都说Command:Sleep。有时,如果我让服务器静置几分钟,它会再次开始工作。如果我重新启动Play应用程序,它会立即重新开始工作。我似乎无法可靠地重新创建导致它的任何事件集。
任何有关从哪里开始寻找的建议或提示都将非常感激,因为这让我疯狂。
[ERROR] from play.core.server.netty.PlayDefaultUpstreamHandler in application-akka.actor.default-dispatcher-186 - Cannot invoke the action
play.api.UnexpectedException: Unexpected exception[SQLTimeoutException: Timeout after 30000ms of waiting for a connection.]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:261) ~[com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:191) ~[com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at play.api.GlobalSettings$class.onError(GlobalSettings.scala:179) [com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at play.api.DefaultGlobal$.onError(GlobalSettings.scala:212) [com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:94) [com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$9$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:158) [com.typesafe.play.play-netty-server_2.11-2.4.1.jar:2.4.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$9$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:155) [com.typesafe.play.play-netty-server_2.11-2.4.1.jar:2.4.1]
at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.util.Failure$$anonfun$recover$1.apply(Try.scala:216) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.util.Try$.apply(Try.scala:192) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.util.Failure.recover(Try.scala:216) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [org.scala-lang.scala-library-2.11.7.jar:na]
at play.api.libs.iteratee.Execution$trampoline$.executeScheduled(Execution.scala:109) [com.typesafe.play.play-iteratees_2.11-2.4.1.jar:2.4.1]
at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:71) [com.typesafe.play.play-iteratees_2.11-2.4.1.jar:2.4.1]
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.concurrent.Promise$class.complete(Promise.scala:55) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:23) [org.scala-lang.scala-library-2.11.7.jar:na]
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) [com.typesafe.akka.akka-actor_2.11-2.3.11.jar:na]
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) [com.typesafe.akka.akka-actor_2.11-2.3.11.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [org.scala-lang.scala-library-2.11.7.jar:na]
Caused by: java.sql.SQLTimeoutException: Timeout after 30000ms of waiting for a connection.
at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:227) ~[com.zaxxer.HikariCP-2.3.7.jar:na]
at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:182) ~[com.zaxxer.HikariCP-2.3.7.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:93) ~[com.zaxxer.HikariCP-2.3.7.jar:na]
at play.api.db.DefaultDatabase.getConnection(Databases.scala:143) ~[com.typesafe.play.play-jdbc_2.11-2.4.1.jar:2.4.1]
at play.api.db.DefaultDatabase.withConnection(Databases.scala:153) ~[com.typesafe.play.play-jdbc_2.11-2.4.1.jar:2.4.1]
at play.api.db.DefaultDatabase.withConnection(Databases.scala:149) ~[com.typesafe.play.play-jdbc_2.11-2.4.1.jar:2.4.1]
at play.api.db.DB$.withConnection(DB.scala:61) ~[com.typesafe.play.play-jdbc_2.11-2.4.1.jar:2.4.1]
at utils.Util$.getCurrentPersonIdAndRole(Util.scala:29) ~[datagem.datagem-1.0-SNAPSHOT-sans-externalized.jar:na]
at utils.globals$UserAction$.invokeBlock(globals.scala:128) ~[datagem.datagem-1.0-SNAPSHOT-sans-externalized.jar:na]
at utils.globals$UserAction$.invokeBlock(globals.scala:122) ~[datagem.datagem-1.0-SNAPSHOT-sans-externalized.jar:na]
at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:493) ~[com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105) ~[com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105) ~[com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:104) ~[com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:103) ~[com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at scala.Option.map(Option.scala:146) ~[org.scala-lang.scala-library-2.11.7.jar:na]
at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:103) ~[com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:96) ~[com.typesafe.play.play_2.11-2.4.1.jar:2.4.1]
at play.api.libs.iteratee.DoneIteratee$$anonfun$mapM$2.apply(Iteratee.scala:741) ~[com.typesafe.play.play-iteratees_2.11-2.4.1.jar:2.4.1]
at play.api.libs.iteratee.DoneIteratee$$anonfun$mapM$2.apply(Iteratee.scala:741) ~[com.typesafe.play.play-iteratees_2.11-2.4.1.jar:2.4.1]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) [org.scala-lang.scala-library-2.11.7.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) [org.scala-lang.scala-library-2.11.7.jar:na]
... 6 common frames omitted
答案 0 :(得分:5)
没关系,我明白了。在代码中的一个位置我使用DB.getConnection而不是DB.withConnection {}而我忘记将连接释放回池中。因此,在调用违规函数10次之后,连接池为空但仍处于活动状态,因此所有其他调用都失败。