Stop called twice on composed system
Closed this issue · 2 comments
Pardon the noobness, I'm sure the issue is 100% my bad but I just can't find the solution.
I have the following composed system defined:
(component/system-map
:core-system
(component/system-map
:a (new-a))
:app
(component/using
(component/system-map
:b (new-b)
[:core-system])))
I start it with:
started-system (component/start-system composed)
and stop it with
(component/stop-system started-system)
At stop time, I notice that :a
is stopped twice. I've made its stop
function idempotent but it still runs twice, as if its state hasn't been nullified on first run.
Any hint for solving this issue would be very appreciated.
I've slightly refactored my approach to this:
(component/system-map
:a (new-a)
:app
(component/using
(component/system-map
:b (new-b)
[:a])))
I prefer this (though it may be incorrect) because :a
is directly accessible by :b
(instead of having to get-in
) and also because I can strictly control what bits of the core system are actually exposed to the app (as you can guess, there are more stuff than just :a
in the core system).
In any case, I still see :a
being stopped twice on shutdown...
Nested systems don't really work. It's easier to compose systems as one flat map with namespaced keys.
See discussion at https://groups.google.com/d/msg/clojure/2-baBp61XTs/ajRgkVZNKjEJ for why lifecycle functions happen twice.