Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala / Slick, "Timeout after 20000ms of waiting for a connection" error

The block of code below has been throwing an error.

  Timeout after 20000ms of waiting for a connection.","stackTrace":[{"file":"BaseHikariPool.java","line":228,"className":"com.zaxxer.hikari.pool.BaseHikariPool","method":"getConnection"

Also, my database accesses seem too slow, with each element of xs.map() taking about 1 second. Below, getFutureItem() calls db.run().

xs.map{ x => 
    val item: Future[List[Sometype], List(Tables.myRow)] = getFutureItem(x)         
    Await.valueAfter(item, 100.seconds) match {
        case Some(i) => i
        case None => println("Timeout getting items after 100 seconds")
    }
}

Slick logs this with each iteration of an "x" value:

[akka.actor.default-dispatcher-3] [akka://user/IO-HTTP/listener-0/24] Connection was PeerClosed, awaiting TcpConnection termination...
[akka.actor.default-dispatcher-3] [akka://user/IO-HTTP/listener-0/24] TcpConnection terminated, stopping
[akka.actor.default-dispatcher-3] [akka://system/IO-TCP/selectors/$a/0] New connection accepted
[akka.actor.default-dispatcher-7] [akka://user/IO-HTTP/listener-0/25] Dispatching POST request to http://localhost:8080/progress to handler Actor[akka://system/IO-TCP/selectors/$a/26#-934408297]

My configuration:

"com.zaxxer" % "HikariCP" % "2.3.2"

default_db {
  url = ...
  user = ...
  password = ...
  queueSize = -1
  numThreads = 16
  connectionPool = HikariCP
  connectionTimeout = 20000
  maxConnections = 40
}

Is there anything obvious that I'm doing wrong that is causing these database accesses to be so slow and throw this error? I can provide more information if needed.

EDIT: I have received one recommendation that the issue could be a classloader error, and that I could resolve it by deploying the project as a single .jar, rather than running it with sbt.

EDIT2: After further inspection, it appears that many connections were being left open, which eventually led to no connections being available. This can likely be resolved by calling db.close() to close the connection at the appropriate time.

EDIT3: Solved. The connections made by slick exceeded the max connections allowed by my mysql config.

like image 514
user2827214 Avatar asked Aug 10 '15 22:08

user2827214


1 Answers

OP wrote:

EDIT2: After further inspection, it appears that many connections were being left open, which eventually led to no connections being available. This can likely be resolved by calling db.close() to close the connection at the appropriate time.

EDIT3: Solved. The connections made by slick exceeded the max connections allowed by my mysql config.

like image 199
Eugene Yokota Avatar answered Oct 30 '22 04:10

Eugene Yokota