All connection pools fail to initialize when one connection pool fails to initialize - scala

Is it a bug?
I am using Playframework 2.6.6 with scala 2.12.3. I have 3 databases defined in application.conf ( the settings for the hikaricp connection pools are all over the map because I experimented with them):
db {
mentions {
driver="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/mentions"
password="***"
username="play"
hikaricp {
maximumPoolSize = 2
minimumIdle=2
}
}
postgres {
driver="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/postgres"
password="***"
username="postgres"
hikaricp {
maximumPoolSize = 9
minimumIdle=9
}
}
sqlserver {
driver="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://10.211.55.5:1433/db"
username="sa"
password="***"
hikaricp {
maximumPoolSize=4
minimumIdle=4
//connectionTestQuery="select 1"
}
}
}
With this configuration the Hikaricp connection pool fails to initialize the sql server connection pool and actually none of the other two connection pools are initialized. The fix for the sql server connection error is to set the connectionTestQuery. That's not the point of this post. I don't understand why the other two connections fail when this one fails. In my mind the other two connection pools should still function.
Here are the error messages from the console:
[info] application - Creating Pool for datasource 'sqlserver'
[error] c.z.h.p.PoolBase - HikariPool-1 - Failed to execute isValid() for connection, configure connection test query (null).
[info] application - Creating Pool for datasource 'sqlserver'
[error] c.z.h.p.PoolBase - HikariPool-2 - Failed to execute isValid() for connection, configure connection test query (null).
[info] application - Creating Pool for datasource 'sqlserver'
[error] c.z.h.p.PoolBase - HikariPool-3 - Failed to execute isValid() for connection, configure connection test query (null).
[error] application -
! #761fipg95 - Internal server error, for (GET) [/] ->
play.api.UnexpectedException: Unexpected exception[CreationException: Unable to create injector, see the following errors:
1) Error injecting method, java.lang.AbstractMethodError
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
at play.api.db.DBModule$$anonfun$$lessinit$greater$1.$anonfun$new$1(DBModule.scala:25):
Binding(interface play.api.db.Database qualified with QualifierInstance(#play.db.NamedDatabase(value=sqlserver)) to ProviderTarget(play.api.db.NamedDatabaseProvider#65c05a8b)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
2) Error injecting method, java.lang.AbstractMethodError
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
at play.api.db.DBModule$$anonfun$$lessinit$greater$1.$anonfun$new$1(DBModule.scala:25):
Binding(interface play.api.db.Database qualified with QualifierInstance(#play.db.NamedDatabase(value=mentions)) to ProviderTarget(play.api.db.NamedDatabaseProvider#700c1d35)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
3) Error injecting method, java.lang.AbstractMethodError
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
at play.api.db.DBModule$$anonfun$$lessinit$greater$1.$anonfun$new$1(DBModule.scala:25):
Binding(interface play.api.db.Database qualified with QualifierInstance(#play.db.NamedDatabase(value=postgres)) to ProviderTarget(play.api.db.NamedDatabaseProvider#1f4f0047)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
3 errors]
at play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:186)
at play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:124)
at play.core.server.AkkaHttpServer.modelConversion(AkkaHttpServer.scala:183)
at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:189)
at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$3(AkkaHttpServer.scala:106)
at akka.stream.impl.fusing.MapAsync$$anon$23.onPush(Ops.scala:1172)
at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:499)
at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:462)
at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:368)
at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:571)
Caused by: com.google.inject.CreationException: Unable to create injector, see the following errors:
1) Error injecting method, java.lang.AbstractMethodError
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
at play.api.db.DBModule$$anonfun$$lessinit$greater$1.$anonfun$new$1(DBModule.scala:25):
Binding(interface play.api.db.Database qualified with QualifierInstance(#play.db.NamedDatabase(value=sqlserver)) to ProviderTarget(play.api.db.NamedDatabaseProvider#65c05a8b)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
2) Error injecting method, java.lang.AbstractMethodError
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
at play.api.db.DBModule$$anonfun$$lessinit$greater$1.$anonfun$new$1(DBModule.scala:25):
Binding(interface play.api.db.Database qualified with QualifierInstance(#play.db.NamedDatabase(value=mentions)) to ProviderTarget(play.api.db.NamedDatabaseProvider#700c1d35)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
3) Error injecting method, java.lang.AbstractMethodError
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
at play.api.db.DBModule$$anonfun$$lessinit$greater$1.$anonfun$new$1(DBModule.scala:25):
Binding(interface play.api.db.Database qualified with QualifierInstance(#play.db.NamedDatabase(value=postgres)) to ProviderTarget(play.api.db.NamedDatabaseProvider#1f4f0047)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
3 errors
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:470)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:176)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at com.google.inject.Guice.createInjector(Guice.java:99)
at com.google.inject.Guice.createInjector(Guice.java:84)
at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:185)
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:137)
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.DevServerStart$$anon$1.$anonfun$reload$3(DevServerStart.scala:174)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
Caused by: java.lang.AbstractMethodError: null
at net.sourceforge.jtds.jdbc.JtdsConnection.isValid(JtdsConnection.java:2833)
at com.zaxxer.hikari.pool.PoolBase.checkDriverSupport(PoolBase.java:456)
at com.zaxxer.hikari.pool.PoolBase.setupConnection(PoolBase.java:423)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:381)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:205)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:448)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:519)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:113)
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:72)
at play.api.db.HikariCPConnectionPool.$anonfun$create$1(HikariCPModule.scala:51)
An update: I still think that architecturally, if one connection pool doesn't work, the other connections pools should not be affected. Today I shutdown my windows vm running sql server and I had only my postgresql server running. The page I tested connected only to the postgresql dbs and it still failed because the sql server connect pool didn't work. This time it failed with a configuration error java.sql.SQLException - Login Timed out.

After doing some debugging in 2.6.6 & 2.6.7, I discovered the following:
java.lang.AbstractMethodError inherits java.lang.IncompatibleClassChangeError which inherits java.lang.LinkageError. java.lang.LinkageError is considered fatal according to the NonFatal object:
object NonFatal {
/**
* Returns true if the provided `Throwable` is to be considered non-fatal, or false if it is to be considered fatal
*/
def apply(t: Throwable): Boolean = t match {
// VirtualMachineError includes OutOfMemoryError and other fatal errors
case _: VirtualMachineError | _: ThreadDeath | _: InterruptedException | _: LinkageError | _: ControlThrowable => false
case _ => true
}
/**
* Returns Some(t) if NonFatal(t) == true, otherwise None
*/
def unapply(t: Throwable): Option[Throwable] = if (apply(t)) Some(t) else None
}
So the Try calls sprinkled all over the code don't catch this exception.
The exception ends up being handled by the guice layers. The call goes back to the guice Initializer.injectAll method which (among other objects) injects the NamedDatabaseProvider objects for each database connection configured in the application.conf file (the binding to the NamedDatabaseProvider is wired in the the DBModule). The NamedDatabaseProvider objects depend on DBApi whose initialization fails every time due to the AbstractMethodError exception which is considered fatal.
Ultimately the problem is a combination of circumstances: 1. the exception throws in the Hikaricp code is fatal, 2. The DBApi code wants to initialize all connection pools and it doesn't handle fatal errors.
I don't consider this a bug. Perhaps the Hickaricp dudes could have thrown an UnsupportedOperationException or something similar.
For others interested I found this: https://github.com/njlg/playdb.

Related

Play Framework is hiding the intial exception

I'm getting this error from Play after implementing a controller. If I throw in a try to catch and println the error, I can see what exception was thrown by my code, but otherwise this information is missing and I get an error relating to files in SBT instead.
What is going on during the handling of my exception that is causing this other exception?
I'm running my application with sbt api/run.
[info] p.c.s.AkkaHttpServer - Listening for HTTP on /[0:0:0:0:0:0:0:0]:9000
(Server started, use Enter to stop and go back to the console...)
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/Users/dan/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/google/inject/guice/4.2.3/guice-4.2.3.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2020-10-15 00:55:32 INFO play.api.http.EnabledFilters Enabled Filters (see <https://www.playframework.com/documentation/latest/Filters>):
play.filters.csrf.CSRFFilter
play.filters.headers.SecurityHeadersFilter
play.filters.hosts.AllowedHostsFilter
play.filters.cors.CORSFilter
2020-10-15 00:55:32 INFO play.api.Play Application started (Dev) (no global state)
2020-10-15 00:55:32 ERROR p.api.http.DefaultHttpErrorHandler Error while handling error
java.lang.ClassCastException: class xsbti.BasicVirtualFileRef cannot be cast to class java.io.File (xsbti.BasicVirtualFileRef is in unnamed module of loader sbt.internal.MetaBuildLoader #6e75aa0d; java.io.File is in module java.base of loader 'bootstrap')
at play.sbt.run.PlayReload$.$anonfun$sourceMap$1(PlayReload.scala:69)
at scala.collection.MapLike$MappedValues.get(MapLike.scala:260)
at play.runsupport.Reloader.$anonfun$findSource$1(Reloader.scala:547)
at scala.Option.flatMap(Option.scala:271)
at play.runsupport.Reloader.findSource(Reloader.scala:546)
at play.core.server.DevServerStart$$anon$1$$anon$2.sourceOf(DevServerStart.scala:171)
at play.core.SourceMapper.$anonfun$sourceFor$1(ApplicationProvider.scala:21)
at play.core.SourceMapper.$anonfun$sourceFor$1$adapted(ApplicationProvider.scala:21)
at scala.collection.ArrayOps$.find$extension(ArrayOps.scala:684)
at play.core.SourceMapper.sourceFor(ApplicationProvider.scala:21)
at play.core.SourceMapper.sourceFor$(ApplicationProvider.scala:20)
at play.core.server.DevServerStart$$anon$1$$anon$2.sourceFor(DevServerStart.scala:169)
at play.api.http.HttpErrorHandlerExceptions$.$anonfun$throwableToUsefulException$1(HttpErrorHandler.scala:358)
at scala.Option.flatMap(Option.scala:283)
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:358)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:261)
at play.filters.cors.AbstractCORSPolicy$$anonfun$1.applyOrElse(AbstractCORSPolicy.scala:128)
at play.filters.cors.AbstractCORSPolicy$$anonfun$1.applyOrElse(AbstractCORSPolicy.scala:126)
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:453)
at play.api.libs.streams.Execution$trampoline$.execute(Execution.scala:70)
at scala.concurrent.impl.Promise$Transformation.submitWithValue(Promise.scala:392)
at scala.concurrent.impl.Promise$DefaultPromise.submitWithValue(Promise.scala:302)
at scala.concurrent.impl.Promise$DefaultPromise.tryComplete0(Promise.scala:249)
at scala.concurrent.impl.Promise$Transformation.handleFailure(Promise.scala:407)
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:469)
at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:56)
at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:93)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:94)
at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:93)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:48)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:48)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
It was an incompatibility between play and sbt, and has been fixed:
https://github.com/playframework/playframework/issues/10486
You end up with this error when an exception happens during handling the server error in the default or custom Play error handler. See play.api.http.HttpErrorHandler.

java.lang.IllegalArgumentException: This Dispatcher has been shut down

I have implemented Spock Integration test TestControllerIntegrationSpec on Grails, Groovy,GROM and Mongodb environment and the Test case has been passed when only one Interation test class available in my development environment.But fails when development environment has more than one Integration test
Ran the test case "gradle clean integrationTest"
This Dispatcher has been shut down.;
nested exception is java.lang.IllegalArgumentException: This Dispatcher has been shut down.
org.springframework.transaction.CannotCreateTransactionException: This Dispatcher has been shut down.; nested exception is java.lang.IllegalArgumentException: This Dispatcher has been shut down.
at org.grails.transaction.ChainedTransactionManager.getTransaction(ChainedTransactionManager.java:127)
at org.grails.transaction.ChainedTransactionManager.getTransaction(ChainedTransactionManager.java:55)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:93)
at com.TestControllerIntegrationSpec.setup(TestControllerIntegrationSpec.groovy)
Caused by: java.lang.IllegalArgumentException: This Dispatcher has been shut down.
at reactor.core.support.Assert.isTrue(Assert.java:61)
at reactor.core.dispatch.AbstractLifecycleDispatcher.dispatch(AbstractLifecycleDispatcher.java:111)
at reactor.bus.EventBus.notify(EventBus.java:368)
at grails.events.Events$Trait$Helper.notify(Events.groovy:111)
at org.grails.events.spring.SpringEventTranslator.onApplicationEvent(SpringEventTranslator.groovy:66)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:382)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:336)
at org.grails.datastore.gorm.events.ConfigurableApplicationContextEventPublisher.publishEvent(ConfigurableApplicationContextEventPublisher.groovy:30)
at org.grails.datastore.mapping.core.AbstractDatastore.publishSessionCreationEvent(AbstractDatastore.java:125)
at org.grails.datastore.mapping.core.AbstractDatastore.connect(AbstractDatastore.java:118)
at org.grails.datastore.mapping.core.AbstractDatastore.connect(AbstractDatastore.java:113)
at org.grails.datastore.mapping.transactions.DatastoreTransactionManager.doGetTransaction(DatastoreTransactionManager.java:101)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:337)
at org.grails.transaction.MultiTransactionStatus.registerTransactionManager(MultiTransactionStatus.java:68)
at org.grails.transaction.ChainedTransactionManager.getTransaction(ChainedTransactionManager.java:106)
... 4 more

spring-boot configure hibernate-ogm for MongoDB

APPLICATION FAILED TO START
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "local" are currently active).
2016-11-10 18:36:52.335 ERROR 1288 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener#d83da2e] to prepare test instance [com.example.DemoApplicationTests#1f68e4e8]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) ~[spring-test-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) ~[spring-test-4.3.4.RELEASE.jar:4.3.4.RELEASE]

Play framework 2.5: ScalikeJDBC: Connection pool is not yet initialized on start

After upgrading to 2.5 version of Play I'm facing this problem when I try to run project in production mode. It seems like in this version I need to initialize pool manually ScalikeJDBC: Connection pool is not yet initialized.(name:'default)
I can't understand how can I do this.
I've added this class:
import play.api.Logger
import scalikejdbc._
import scalikejdbc.config._
class DbInitializer {
DBs.setupAll()
Logger.debug("DB initialized")
}
and in my module mark it as EagerSingleton:
class GlobalModule extends AbstractModule {
def configure() = {
bind(classOf[DbInitializer]).asEagerSingleton()
}
}
Now when I run my project in production I see:
[info] application - Creating Pool for datasource 'default' [info]
p.a.d.DefaultDBApi - Database [default] connected at
jdbc:postgresql://localhost:5432/inetshop [debug] application -
[debug] application - DB initialized
Oops, cannot start the server. com.google.inject.CreationException:
Unable to create injector, see the following errors:
1) Error injecting constructor, java.lang.IllegalStateException:
Connection pool is not yet initialized.(name:'default) at
controllers.Application.(Application.scala:20)
So my Initializer run successfully but still facing this problem. Need help to fix this.
I've had a similar problem, (Connection pools settings were ignored) not exactly the same, but maybe it helps:
we had to enable the scalikejdbc-play-dbapi-adapter:
build.sbt:
"org.scalikejdbc" %% "scalikejdbc-play-dbapi-adapter" %
and add to application.conf:
play.modules.enabled += "scalikejdbc.PlayDBApiAdapterModule"

Slick and bonecp: org.postgresql.util.PSQLException: FATAL: sorry, too many clients already error

Locally when I am developing my application I launch my play2 application using sbt run
I love how I can make code changes, and then reload my browser to see my changes.
After about roughly 10 code changes or so, I get a postgresql too many connection error (see below).
My db connection is using the below DatabaseAccess.scala class.
I'm guessing on each reload it is creating a bunch of connections to postgresql. In my Global am currently doing:
override def onStart(app: Application) {
Logger.info("Global.onStart")
DatabaseAccess.loadConfiguration()
}
In production I am also worried that if I make multiple deploys in a short period of time, or start/stop my service I might run into this problem also.
How can I ensure all connections are destroyed? I know I can either put something in the onStart or OnStop but I'm not really sure how to clear the connections that might have existed previously. (assuming this isn't a bug)
I did create a release() method that I was calling on onStop but that didn't seem to work:
def release() {
configs = Map[String, BoneCPConfig]()
dataSources = Map[String, BoneCPDataSource]()
databases = dataSources.map { case(key, value) => (key, Database.forDataSource(value)) }
}
All I did was re-init the vars so I guess that wasn't really what I needed to do.
My data access pattern is as follows:
def getById(userId: Int): Option[User] = {
db.withSession { implicit session =>
return userDao.getById(userId)
}
}
My database access class looks like:
https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/unfiltered/src/main/scala/DatabaseAccess.scala
My application.conf connection looks like:
#postgresql
db.default.driver="org.postgresql.Driver"
db.default.url = "jdbc:postgresql://localhost/testweb_development"
db.default.user = "testdbuser"
db.default.password = ""
db.default.minConnections = 4
db.default.maxConnections = 24
db.default.maxThreads = 2
Locally when developing after about approximately 10 code changes and sbt doing it's nice partial class reloads I get this error:
play.api.Application$$anon$1: Execution exception[[SQLException: Unable to open a test connection to the given database. JDBC url = jdbc:postgresql://localhost/testweb_development, username = testdbuser. Terminating connection pool (set lazyInit to true if you expect to start your database after your app). Original Exception: ------
org.postgresql.util.PSQLException: FATAL: sorry, too many clients already
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:291)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:108)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:30)
at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393)
at org.postgresql.Driver.connect(Driver.java:267)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:363)
at com.jolbox.bonecp.BoneCP.<init>(BoneCP.java:416)
at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:120)
at scala.slick.jdbc.JdbcBackend$DatabaseFactoryDef$$anon$4.createConnection(JdbcBackend.scala:47)
at scala.slick.jdbc.JdbcBackend$BaseSession.conn$lzycompute(JdbcBackend.scala:302)
at scala.slick.jdbc.JdbcBackend$BaseSession.conn(JdbcBackend.scala:302)
at scala.slick.jdbc.JdbcBackend$BaseSession.close(JdbcBackend.scala:316)
at scala.slick.backend.DatabaseComponent$DatabaseDef$class.withSession(DatabaseComponent.scala:31)
at scala.slick.jdbc.JdbcBackend$DatabaseFactoryDef$$anon$4.withSession(JdbcBackend.scala:46)
at com.exampleapp.services.UserServiceImpl.getById(UserService.scala:37)
at controllers.UsersController$$anonfun$show$1.apply(UsersController.scala:84)
at controllers.UsersController$$anonfun$show$1.apply(UsersController.scala:76)
at play.api.mvc.ActionBuilder$$anonfun$apply$10.apply(Action.scala:221)
at play.api.mvc.ActionBuilder$$anonfun$apply$10.apply(Action.scala:220)
at controllers.ActionWithContext$.invokeBlock(BaseController.scala:42)
at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:309)
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:109)
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:109)
at play.utils.Threads$.withContextClassLoader(Threads.scala:18)
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:108)
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:107)
at scala.Option.map(Option.scala:145)
at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:107)
at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:100)
at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:481)
at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:481)
at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:517)
at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:517)
at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$13.apply(Iteratee.scala:493)
at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$13.apply(Iteratee.scala:493)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
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)
Environment
I am running scala 2.10.3, play 2.2.3
I am launching my app using sbt run.
Postgresql driver version: 9.1-901.jdbc4
slick version: 2.0.1
bonecp version: 0.8.0.RELEASE
Slick handles session closing automatically. From the documentation:
The Database object’s withSession method creates a Session, passes it to a given function and closes it afterwards. If you use a connection pool, closing the Session returns the connection to the pool.
The problem is the Bonecp's dataSource connections which are not closed, as showed on this gist you need to close them manually using dataSource.close().