Fork me on GitHub
#biff
<
2022-12-14
>
m.q.warnock15:12:06

a word to the [un]wise: I added a new file with a use-thingy fn, which didn't need a stop hook, so I elided the usual update sys :biff/stop conj stop! call. I then hacked on things for about 4 hours, and I'm fairly certain I restarted the whole system during that time, and things kept working, until I started doing something in a comment-block that deref'ed biff/system - suddenly (or so I thought) it was nil! Requests continued to be successfully served[1], and I flailed about quite a bit, before realizing that, of course, my use-thingy fn needed to return sys, even unaltered. Just something to keep in mind (or maybe something biff could sanity-check?); hope this post saves someone a headache, preemptively or upon searching. (key-phrase: "why is my @biff/system nil?") 1. I'm still slightly curious about this, but I guess it being the last-called use-whatever fn gave other components the opportunity to get a reference that didn't evaporate?

Jacob O'Bryant22:12:16

Ah yes, make sure to return the system map 🙂 . > I'm still slightly curious about this, but I guess it being the last-called use-whatever fn gave other components the opportunity to get a reference that didn't evaporate? The com.biffweb/system var is only used from the biff/start-system / biff/refresh functions. In all other cases, component functions take the system map value they get called with and pass it on to their children. e.g. request handlers receive the system map merged with the ring request because the (excellently named) biff/use-outer-default-middleware component includes some middleware that merges in the system map: • https://github.com/jacobobryant/biff/blob/master/src/com/biffweb.clj#L333https://github.com/jacobobryant/biff/blob/master/src/com/biffweb/impl/middleware.clj#L126https://github.com/jacobobryant/biff/blob/master/src/com/biffweb/impl/middleware.clj#L110 This does mean that any keys which are added to the system map by components which run after biff/use-outer-default-middleware will not be visible to request handlers.

Jacob O'Bryant22:12:18

> or maybe something biff could sanity-check? I think that's reasonable; I'll throw it in my notes.

Jacob O'Bryant22:12:36

If you called biff/refresh while @biff/system was nil, it probably just did a no-op, or at least a partial no-op. i.e. it'd call clojure.tools.namespace.repl/refresh, but it wouldn't actually call any of the stop functions, and it wouldn't call start-system again afterward.

m.q.warnock23:12:24

by “restarted the whole system” i mean i ctrl-c’ed the jvm; i would have guessed something –if only in my own code – would have broken with biff/system being nil after start-system. i guess that’s my many years of writing in c++ and its ilk showing ;)

m.q.warnock23:12:35

i just realized something i was confused by some time ago – where i tried to add an atom to the system map from a use-something fn and couldn’t find it in my middleware – is explained in your reply; i quickly got past it by adding it to the initial system declaration (seemed like a better place to put such things anyway), but it might be a good thing to mention in the docs, for those (like me) too lazy to fully read/understand that code-path

Jacob O'Bryant00:12:03

ah, I see what you meant. I'll make a note for that about the docs as well. perhaps in the "system composition" section?

👍 1