This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-20
Channels
- # announcements (3)
- # babashka (7)
- # beginners (43)
- # biff (19)
- # calva (39)
- # cider (16)
- # clerk (2)
- # clj-yaml (32)
- # cljs-dev (37)
- # clojure (129)
- # clojure-australia (1)
- # clojure-china (1)
- # clojure-europe (46)
- # clojure-filipino (1)
- # clojure-gamedev (25)
- # clojure-hk (1)
- # clojure-indonesia (1)
- # clojure-japan (2)
- # clojure-korea (1)
- # clojure-my (1)
- # clojure-nl (5)
- # clojure-norway (8)
- # clojure-sg (1)
- # clojure-sweden (12)
- # clojure-taiwan (1)
- # clojure-uk (9)
- # clojurescript (14)
- # core-typed (136)
- # cursive (18)
- # duct (9)
- # emacs (12)
- # etaoin (7)
- # events (1)
- # graalvm (3)
- # gratitude (2)
- # humbleui (7)
- # hyperfiddle (99)
- # introduce-yourself (5)
- # jobs (2)
- # leiningen (1)
- # missionary (14)
- # nrepl (2)
- # off-topic (12)
- # polylith (21)
- # rdf (29)
- # re-frame (8)
- # releases (1)
- # shadow-cljs (264)
- # spacemacs (21)
- # sql (7)
- # vscode (1)
I'm doing some maintenance on an old duct
-based app (and learning duct) and noticed that if something goes wrong when starting the system for local development (e.g. local database was not running), integrant.repl
will catch the exception and call (ig/halt! system)
and then print the error. Halting the system will call the ig/halt-key!
on the components (regardless whether they were running or not). However, it looks like some components (e.g. :duct.database.sql/hikaricp
) don't handle such cases and fail, thus throwing more exceptions and hiding the original problem. Is this expected or am I doing something wrong?
in other words,
(defmethod ig/halt-key! :duct.database.sql/hikaricp [_ {:keys [spec]}]
(when spec ;; <- !!
(let [ds (unwrap-logger (:datasource spec))]
(hikari-cp/close-datasource ds))))
Hey. I personally found hikarycp not very usefull. especially older versions. We switched to use the c3p0 library https://github.com/swaldman/c3p0 and it works fine with Duct
something like this
(defmethod ig/init-key :app.db/c3p0 [_ {:keys [jdbc-url]}]
(let [datasource-options (merge default-datasource-options
{:connection-uri jdbc-url})
datasource (c3p0/make-datasource-spec datasource-options)]
(sql/->Boundary
(update datasource :datasource
(fn [ds]
(wrap-logger ds))))))
(defmethod ig/halt-key! :app.db/c3p0 [_ {:keys [spec]}]
(unwrap-logger (:datasource spec))
(.close spec))
Sure, I have no doubt there's better connection poolin tools around. But my (perhaps poorly worded) question was really about the signature of ig/halt-key!
; should your function make assumptions whether spec
can be nil or not
If a component raises an exception while being initiated, it isn't included in the system and therefore shouldn't be halted, so I'm a little confused at what's going on in this case. Is HikariCP starting, something else failing, and that fail somehow causes HikariCP to fail as well?
that's a good question.
What originally happened was I accidentally started the app without starting a local dockerized db. It took me a few moments to realize this because the first symptom of anything going wrong was a NPE from a completely unrelated component running the halt-key!
method that somehow destructured a nil
value from the second argument (similar to the spec
in the above c3p0 code example). Okay, so I added a (when whatever ...
to that component and of course now the NPE was thrown from yet another component (the duct hikari component in this case). At this point I got rather confused as usually when I encounter startup problems with integrant I get that "error on key foo when starting system" -style exception and started to wonder if this is some feature of duct (of which I know very little) or is there something wrong with our app setup.
Of course, at the end of the day this is a rather trivial matter, but I'd sure like to know what's going on 🙂
I think I'll just need to produce a minimal repro of this if I can.
I think the problem has something to do with mixing a rather old 0.6.2 duct (and integrant) with a newer 0.3.1 integrant-repl. At least sometimes I could get a scenario where the halt-key!
method was called for not-yet-initialized components with a nil
value. Perhaps this is the same thing as https://github.com/weavejester/integrant/issues/40