Fork me on GitHub

@seancorfield You’re probably right that I miss-read the docs. I did use with-db-connection, but in my scenario, the connection is sometimes lost, and I’m not sure the macro handles this, right?


Anyway, a way for me to deal with this is to have an atom with a connection, and then once in a while make a new connection if the old fails.


If you or anyone else know a better strategy for this kind of resilience, I’d be very happy to know 🙂


@grav Using an atom for the connection sounds like a terrible hack to me. with-db-connection will open the connection, run the body of the form, and then close the connection. It shouldn't get "sometimes lost" unless you have a flaky database or a flaky network?


I'd recommend reading the docs for Reusing Connections and considering a connection pool (we use c3p0 heavily at work, I've heard other folks praise Hikari, and there are a few other options).


If you use a connection pooling library, bad connections should automatically be dropped and new connections created. But if connections are going bad (due to network/DB issues) you would have to decide whether to retry a given (set of) SQL operation(s). That's true regardless, since "the network is broken", and applications all need to build in resilience somehow for failures of any external interactions.