I am playing with next-jdbc and I’m quite liking it. I like the fact that you can use a literal or a Connection and it just works- for the REPL it’s great.
Still, I don’t understand why, if I have a database:
Will sooner or later die with an error like Execution error (ConnectException) at java.net.PlainSocketImpl/socketConnect (PlainSocketImpl.java:-2). Can't assign requested address (connect failed).
My first reaction is that is a bug, suggesting that database connections are not always being correctly closed in that first example (they should be tho’).
I will investigate and update this thread with my findings.
I will update the bug on GitHub - thanks for posting.
I think my question here was more on the informative side: are connections obtained as get-datasource closed on every use? and is there any difference between the def and the with-opencases? because I see the connection identifiers in Maria go up a lot.
If you pass a DataSource (or db-spec hash map or URI string) to any of next.jdbc's APIs that accept such a thing, then next.jdbc will call .getConnection() (possibly after creating a DataSource from the hash map or string) to get a fresh connection and will close it before returning the result. next.jdbc uses with-open internally to ensure all things that get opened – which includes Connection, PreparedStatement, and a few other things – also get properly closed.
The basic javax.sql.DataSource does not have a .close method (and doesn’t need one). HikariCP, c3p0, etc that provide connection pooled datasources have methods to shutdown the pool and those are usually named .close (but there’s no common base type to use for type hinting – I discuss that in the next.jdbc docs).
For folks reading this thread and not looking at the test results added to the GitHub issue above, it seems that this issue is related to a specific combination of environmental features, related to running MariaDB server on macOS (possibly restricted to specific versions of those).