sql

emccue 2025-08-29T10:57:50.843259Z

digging into the nitty gritty: what is the purpose of this (locking this. It feels strange to be locking on a method param

(extend-protocol p/Transactable
  java.sql.Connection
  (-transact [this body-fn opts]
    (let [raw (raw-connection this)]
      (cond
        (and (not (contains? *active-tx* raw)) (= :ignore *nested-tx*))
        ;; #245 do not lock when in c.j.j compatibility mode:
        (binding [*active-tx* (conj *active-tx* raw)]
          (transact* this body-fn opts))
        (or (not (contains? *active-tx* raw)) (= :allow *nested-tx*))
        (locking this
          (binding [*active-tx* (conj *active-tx* raw)]
            (transact* this body-fn opts)))

p-himik 2025-08-29T11:12:55.995779Z

It's locking on an instance of java.sql.Connection. And that class is not thread-safe.

emccue 2025-08-29T11:13:28.201799Z

right - but why

emccue 2025-08-29T11:13:47.921049Z

almost everything else (i think) is assuming single threaded use...right?

p-himik 2025-08-29T11:14:09.060349Z

Not at all, why would you assume that?

emccue 2025-08-29T11:16:06.668629Z

the try/finallys with calls to .set*

p-himik 2025-08-29T11:16:45.884509Z

But those are within the critical section, no?