seancorfield / next-jdbc

A modern low-level Clojure wrapper for JDBC-based access to databases.
https://cljdoc.org/d/com.github.seancorfield/next.jdbc/
Eclipse Public License 1.0
768 stars 90 forks source link

Mutable transaction on connection is not thread safe #106

Closed seancorfield closed 4 years ago

seancorfield commented 4 years ago

Is your feature request related to a problem? Please describe. If you run transactions directly on a single Connection across multiple threads, they can interfere with each other. Consider providing a way to isolate them.

Describe the solution you'd like Some built-in isolation between transactions executed on the same Connection object. Optionally, providing some opt-in or opt-out control via the opts hash map.

Describe alternatives you've considered Wrapping with-transaction calls in user code with locking on the "transactable" but this is overkill for DataSource (pooled connections).

seancorfield commented 4 years ago

The change in 905f7c3 only adds locking on the Connection if it was an existing connection being passed in. If with-transaction/transact is passed a DataSource or some other non-Connection object from which to obtain a DataSource (e.g., a JDBC URL or a db-spec hash map), locking is not used because the Connection object is created locally to the transaction code.

seancorfield commented 4 years ago

This was released in 1.0.445!