I'm having a problem with the session and connection handling in play with Slick 2.0.1 and play-slick 0.6.0.1
The error is
[SQLException: Timed out waiting for a free available connection.]
[...]
Caused by: java.sql.SQLException: Timed out waiting for a free available connection.
at com.jolbox.bonecp.DefaultConnectionStrategy.getConnectionInternal(DefaultConnectionStrategy.java:88) ~[bonecp.jar:na]
[...]
I have a play base controller trait for setting up the explicit session in one place
trait BaseController extends Controller with Secured {
import play.api.Play.current
implicit def session: SessionDef = play.api.db.slick.DB.withSession {
implicit session => {session}
}
}
Then there is the /list action with a simple call to a UserService using the explicit session:
object List extends BaseController with Secured {
def index = IsAuthenticated { username =>
implicit request =>
UserService.findByEmail(username).map { user =>
Ok(views.html.List.index(user))
}.getOrElse(Forbidden)
}
}
I have removed all async actions so I don't think this question would be a duplicate of similar questions: Play slick and Async - is it a race condition? or Scala Play 2.2 Slick 1.0.1 - future { Try {...} } Timed out waiting for a free available connection
The issue occurs after reloading the action about 10 times.
Obviously I'm doing something wrong in the session handling of slick - are there any good examples of slick 2 session handling in playframework? What would be the best practice for that?
edit: One possible source of the issue might be an object that I use for holding the TableQueries
object Models {
val users = TableQuery[Users]
val mailinglists = TableQuery[Mailinglists]
val mailinglistMemberships = TableQuery[MailinglistMemberships]
}
If that may be the source of the problem, what would be a good place to put these references? The main reason for the object is to reference these instances in the foreign keys of the table definition (similar to http://slick.typesafe.com/doc/2.0.1/schemas.html#constraints)
edit: Here's the code for findByEmail - but I don't think it really matters. It seems to be the same behavior and problem in all queries.
def findByEmail(email: String)(implicit session: Session): Option[User]
= Models.users.filter(_.email === email).firstOption
I'd be thankful for any hint into the right direction.