我无法维护与ClearDB实例的连接。当我的应用程序第一次运行时,我可以向它请求访问数据库就好了。一两分钟后,如果我提出相同的请求,我会收到通信链接失败。以下是我申请的详细信息:
如果我在本地针对我的本地MySQL实例运行我的应用程序,我无法重现该问题。如果我将我的DB URL更改为指向我的ClearDB实例,我可以在本地重现它。绝对看起来像一个ClearDB问题...
我联系了ClearDB支持,他们告诉我他们无法帮助我,因为他们不直接支持Spray.io,我应该尝试直接从Heroku获得帮助。我已经向Heroku发送了一个帮助请求,但并没有期待太多,因为我认为Spray.io或Slick也没有直接支持。我一直在搜索Stackoverflow而没有运气,所以我现在发布这个。
下面是我在本地重现时获得的完整堆栈跟踪。
java.lang.x:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 185,507 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 185,507 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)[WARN] [01/26/2014 20:48:42.906] [LottoREST-akka.actor.default-dispatcher-4] [akka://LottoREST/user/lotto-service] Request HttpRequest(GET,http://localhost:8080/drawing,List(Cookie: JSESSIONID=4EFAE21258F8AF891C010DD14F9BC3F1, Accept-Language: en-US, en, Accept-Encoding: gzip, deflate, sdch, User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36, Cache-Control: max-age=0, Connection: keep-alive, Host: localhost:8080),Empty,HTTP/1.1) could not be handled normally
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3720)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4160)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2825)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2156)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989)
at scala.slick.jdbc.StatementInvoker.results(StatementInvoker.scala:34)
at scala.slick.jdbc.StatementInvoker.elementsTo(StatementInvoker.scala:17)
at scala.slick.jdbc.Invoker$class.foreach(Invoker.scala:90)
at scala.slick.jdbc.StatementInvoker.foreach(StatementInvoker.scala:10)
at scala.slick.jdbc.Invoker$class.build(Invoker.scala:66)
at scala.slick.jdbc.StatementInvoker.build(StatementInvoker.scala:10)
at scala.slick.jdbc.Invoker$class.list(Invoker.scala:56)
at scala.slick.jdbc.StatementInvoker.list(StatementInvoker.scala:10)
at scala.slick.jdbc.UnitInvoker$class.list(Invoker.scala:150)
at scala.slick.driver.BasicInvokerComponent$QueryInvoker.list(BasicInvokerComponent.scala:19)
at com.megalottopools.model.DrawingComponent$Drawings$.findAllDrawings(Drawing.scala:28)
at com.megalottopools.model.Model.getDrawings(Model.scala:20)
at com.megalottopools.api.DrawingService$$anonfun$1.apply(DrawingService.scala:27)
at com.megalottopools.api.DrawingService$$anonfun$1.apply(DrawingService.scala:25)
at spray.routing.directives.BasicDirectives$$anonfun$mapRequestContext$1$$anonfun$apply$1.apply(BasicDirectives.scala:30)
at spray.routing.directives.BasicDirectives$$anonfun$mapRequestContext$1$$anonfun$apply$1.apply(BasicDirectives.scala:30)
at spray.routing.directives.BasicDirectives$$anon$3$$anonfun$happly$1.apply(BasicDirectives.scala:92)
at spray.routing.directives.BasicDirectives$$anon$3$$anonfun$happly$1.apply(BasicDirectives.scala:92)
at spray.routing.RouteConcatenation$RouteConcatenation$$anonfun$$tilde$1.apply(RouteConcatenation.scala:30)
at spray.routing.RouteConcatenation$RouteConcatenation$$anonfun$$tilde$1.apply(RouteConcatenation.scala:29)
at spray.routing.directives.BasicDirectives$$anonfun$mapRequestContext$1$$anonfun$apply$1.apply(BasicDirectives.scala:30)
at spray.routing.directives.BasicDirectives$$anonfun$mapRequestContext$1$$anonfun$apply$1.apply(BasicDirectives.scala:30)
at spray.routing.directives.BasicDirectives$$anon$3$$anonfun$happly$1.apply(BasicDirectives.scala:92)
at spray.routing.directives.BasicDirectives$$anon$3$$anonfun$happly$1.apply(BasicDirectives.scala:92)
at spray.routing.RouteConcatenation$RouteConcatenation$$anonfun$$tilde$1.apply(RouteConcatenation.scala:30)
at spray.routing.RouteConcatenation$RouteConcatenation$$anonfun$$tilde$1.apply(RouteConcatenation.scala:29)
at spray.routing.RouteConcatenation$RouteConcatenation$$anonfun$$tilde$1.apply(RouteConcatenation.scala:30)
at spray.routing.RouteConcatenation$RouteConcatenation$$anonfun$$tilde$1.apply(RouteConcatenation.scala:29)
at spray.routing.directives.BasicDirectives$$anonfun$mapRequestContext$1$$anonfun$apply$1.apply(BasicDirectives.scala:30)
at spray.routing.directives.BasicDirectives$$anonfun$mapRequestContext$1$$anonfun$apply$1.apply(BasicDirectives.scala:30)
at spray.routing.directives.ExecutionDirectives$$anonfun$handleExceptions$1$$anonfun$apply$4.apply(ExecutionDirectives.scala:35)
at spray.routing.directives.ExecutionDirectives$$anonfun$handleExceptions$1$$anonfun$apply$4.apply(ExecutionDirectives.scala:33)
at spray.routing.HttpServiceBase$class.runSealedRoute$1(HttpService.scala:36)
at spray.routing.HttpServiceBase$$anonfun$runRoute$1.applyOrElse(HttpService.scala:46)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425)
at akka.actor.ActorCell.invoke(ActorCell.scala:386)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230)
at akka.dispatch.Mailbox.run(Mailbox.scala:212)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:506)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3166)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3620)
... 51 more
答案 0 :(得分:0)
听起来像连接超时问题。检查c3p0是否可以正确保持与ClearDB的连接。某些数据库连接池使用网络ping或运行简单的选择语句(如SELECT 1
)来保持连接活动。您可以检查数据库可用的配置选项。要验证这是一个问题,请每隔几秒运行一次虚拟数据库操作,看看一段时间后是否收到相同的错误(保持池大小== 1)。