0

I am unable to maintain connections to my ClearDB instance. When my app first runs, I can make a request to it which accesses the DB just fine. After a minute or two, if I make the same request, I get a communications link failure. Here are the details of my application:

  • Scala using Spray.io
  • Slick for DB interaction
  • ClearDB:ignite while testing this new application
  • DataSource class: com.mchange.v2.c3p0.ComboPooledDataSource

If I run my application locally against my local MySQL instance, I can not reproduce the problem. If I change my DB URL to point to my ClearDB instance, I can reproduce this locally. Definitely seems like a ClearDB issue...

I contacted ClearDB support and they told me that they can't help me because they don't directly support Spray.io and that I should try to get help from Heroku directly. I've sent a help request to Heroku but not expecting much since I don't think Spray.io or Slick are directly supported there either. I've been scouring Stackoverflow as well with no luck so I'm posting this now.

Below is the full stack trace I get when I reproduce locally.

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
ShatyUT
  • 1,375
  • 2
  • 14
  • 28

1 Answers1

0

Sounds like a connection timeout issue. Check that c3p0 can properly keep connections to ClearDB alive. Some DB connection pools use either network ping or run simple select statements like SELECT 1 to keep connections alive. You can check what configuration options are available for your DB. To verify that this is an issue run some dummy db ops every few seconds and see if you get the same error after a while (keep pool size == 1).

yǝsʞǝla
  • 16,272
  • 2
  • 44
  • 65
  • I do have the "preferred test query" set to be "SELECT 1" but I'm not sure how to know whether c3p0 is actually using that. I'll see if I can set up a regular call to the DB every 60 seconds or so to see if that works. Seems like I should not have to do that though. I don't have access to the DB config options. I did contact ClearDB support and they checked that all my options are set correctly...whatever that means. – ShatyUT Jan 27 '14 at 15:16