sql

All things SQL and JDBC...
benny 2020-08-14T17:36:25.479Z

i’m pretty sure i’m using with* etc the way i should which should dispose of my connections properly without manual intervention but i now hit a threshold somehow that i can’t even run my tests without getting the following error. in the past it would happen after using my repl long enough, but now it’s happening during a full test. any common pitfalls? i did look through the docs 😉 > Caused by: org.postgresql.util.PSQLException: FATAL: sorry, too many clients already

2020-08-14T17:44:46.483Z

there should be some way to ask postgres how many connected clients it has, you should do that and see if you get an expected amount. for unix like operating systems there are commands to list open tcp connections, you should run those and see how many open sockets are connected to postgres, you should do a bisecting search by disabling half your test suite over and over to see if you can isolate a particular case/test/file etc

2020-08-14T17:47:28.484Z

or you could just use a connection pool library and configure it to never hand out too many connections

benny 2020-08-14T17:47:40.484200Z

i’m using hikari

benny 2020-08-14T17:47:46.484600Z

which is why i’m especially surprised

benny 2020-08-14T17:48:21.485200Z

specifically hikari-cp

2020-08-14T17:48:31.485500Z

do you know what the max client limit for your postgres install is and is hikari configured not to exceed that?

2020-08-14T17:48:59.486200Z

are you running multiple instances of your code and exceeding the limit that way?

benny 2020-08-14T17:49:00.486300Z

i was trying to figure out how to line those up, i’m using the pg docker image and hikari pool defaults

benny 2020-08-14T17:49:29.486600Z

max_connections in pg is 100

benny 2020-08-14T17:50:11.487100Z

maximumPoolSize in hikari is 10 :thinking_face:

2020-08-14T17:50:54.487400Z

are you creating multiple hikari pools?

benny 2020-08-14T17:51:25.488200Z

hm…

2020-08-14T17:51:27.488300Z

e.g. do you create a single pool somewhere and explicitly re-use it?

benny 2020-08-14T17:51:37.488600Z

i’m using an atom in my test util

benny 2020-08-14T17:51:44.488900Z

and i’m maybe resetting that a ton

benny 2020-08-14T17:51:56.489100Z

looks like it

2020-08-14T17:53:29.490500Z

connection pools tend to create connections immediately and keep them alive, so if you create 10 pools your connections are all used up regardless of if you are using those pools or not

benny 2020-08-14T17:56:33.491600Z

is there a way to re-use a pool across tests then? i believe lein runs tests in parallel so even if i check if it’s been set, it’s a race condition

2020-08-14T17:57:29.491900Z

lein does not run tests in parallel

benny 2020-08-14T18:00:31.493100Z

i was checking wrong, that did it, thanks @hiredman!

benny 2020-08-14T18:00:36.493300Z

you lead me down the right path 🙂