Idempotency
martinklepsch opened this issue · 2 comments
The Component README recommends start/stop methods to be idempotent. Many components in system
do not have idempotent start/stop methods, see for example HttpKit:
(defrecord WebServer [options server handler]
component/Lifecycle
(start [component]
(let [handler (get-in component [:handler :handler] handler)
server (run-server handler options)]
(assoc component :server server)))
(stop [component]
(when server
(server)
component)))
If I understand correctly start will start multiple servers if called repeatedly and stop won't remove the key from the component causing the httpkit's stop function to be called repeatedly (which it might just tolerate).
@danielsz Is this something you'd like to change or is that in your experience just not very important? (I don't have much experience with component so you probably know better :)
Hi @martinklepsch,
You are 100% right. Many components are not idempotent (yet).
It is also true that it is not very important in my use case, where I restart the system in the REPL, where stop is always called before start. I do however encourage contributors to send patches to make components they care about idempotent. Very recently someone did exactly that (for the mongodb component, I believe).
So if there is a component you'd rather have idempotent, by all means prepare a PR and I'll merge happily.