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
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
or you could just use a connection pool library and configure it to never hand out too many connections
i’m using hikari
which is why i’m especially surprised
specifically hikari-cp
do you know what the max client limit for your postgres install is and is hikari configured not to exceed that?
are you running multiple instances of your code and exceeding the limit that way?
i was trying to figure out how to line those up, i’m using the pg docker image and hikari pool defaults
max_connections in pg is 100
maximumPoolSize in hikari is 10 :thinking_face:
are you creating multiple hikari pools?
hm…
e.g. do you create a single pool somewhere and explicitly re-use it?
i’m using an atom in my test util
and i’m maybe resetting that a ton
looks like it
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
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
lein does not run tests in parallel
i was checking wrong, that did it, thanks @hiredman!
you lead me down the right path 🙂