0

I wrote a server which connects to postgresql via slick when a client send a request. Now I have one client that sends request every 1 second. The problem is after several times, the below error raised:

[SEVERE][slick.psql.db connection adder][Driver] Connection error: org.postgresql.util.PSQLException: FATAL: sorry, too many clients already
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:438)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:222)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:450)
at org.postgresql.Driver.connect(Driver.java:252)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:117)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:123)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:365)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:194)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:460)
at com.zaxxer.hikari.pool.HikariPool.access$100(HikariPool.java:71)
at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:697)
at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:683)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

This is my config for slick postgres:

psql {

profile="slick.jdbc.PostgresProfile$"
driver="slick.driver.PostgresDriver$"
db {
  driver="org.postgresql.Driver"
  url="jdbc:postgresql://localhost:5432/mydb"
  user=postgres
  password=123
  numThreads=2
  queueSize=100
}

}

And postgres config says max_connection = 100 Here, the code on server side ran for 50 times(queueSize/numThreads) then showed error.

Also, this is a config for db connection:

lazy val psqlDbConfig: DatabaseConfig[PostgresProfile] = DatabaseConfig.forConfig("psql")
val psqlDb: JdbcBackend#DatabaseDef = psqlDbConfig.db

//sql commands
 psqlDb.run(sql""" select * from mytable  """.as[MyObj])

}

I supposed that when max connection is reached hikari must release them and manage pool but this case not happened.

ArefehTam
  • 367
  • 1
  • 6
  • 20

0 Answers0