문제

I am using play-slick in a play 2.1.3 application.
Here is the code to insert a record

  def insert = DBAction { implicit rs =>
    recordForm.bindFromRequest.fold (
        formWithErrors => {
          Redirect(HomePage).flashing("alert-error" -> "Enter proper values")
        },
        record => {
          Records.insert(record)
          Redirect(HomePage).flashing("alert-success" -> "Record inserted successfully")
        }
    )            
  }

The above code is leaking connection and the application throws the below error after 30+ requests

java.sql.SQLException: Timed out waiting for a free available connection.
    at com.jolbox.bonecp.BoneCP.getConnection(BoneCP.java:503) ~[bonecp.jar:0.7.1.RELEASE]
    at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:114) ~[bonecp.jar:0.7.1.RELEASE]
    at scala.slick.session.PlayDatabase.createConnection(PlayDatabase.scala:9) ~[na:na]
    at scala.slick.session.BaseSession.conn$lzycompute(Session.scala:207) ~[slick_2.10-1.0.1.jar:1.0.1]
    at scala.slick.session.BaseSession.conn(Session.scala:207) ~[slick_2.10-1.0.1.jar:1.0.1]
    at scala.slick.session.Session$class.prepareStatement(Session.scala:29) ~[slick_2.10-1.0.1.jar:1.0.1]

Similar issues are reported, but this code is slightly different.
Any idea?

도움이 되었습니까?

해결책

This is probably an instance of the bug "2)" described in https://github.com/freekh/play-slick/issues/81 . It is fixed in play-slick master and will be in the next release. The buggy code in play-slick is explained here Play slick and Async - is it a race condition? . The bug triggers a follow-up bug in Slick, where instead of an exception thrown, the connection is leaked: https://github.com/slick/slick/pull/107

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top