manifold
manifold copied to clipboard
long chains of Deferred values hang
i came across this while debugging another problem
(defn chain-delay-deferred
[n t]
(let [f (manifold.deferred/deferred)]
(future (Thread/sleep t) (manifold.deferred/success! f 100))
(reduce (fn [d i] (manifold.deferred/chain d (fn [v] (+ v i))))
f
(range 0 n))))
@(chain-delay-deferred 100 1000) ;; 5050
@(chain-delay-deferred 100000 1000) ;; hangs
there are some values of n where it hangs on some runs and returns on other runs. on my machine
@(chain-delay-deferred 4567 1000)
seems to hang about half the time
i ran this against the current tip of master 4e1fff70c5380b33e9cc2f50f03ce16af6d393b4
, but i was observing the same problem against 0.1.1-alpha3
I think this is due to stack overflows, but I'll look into it.
that would make sense... should an error not propagate though ?
tho i guess there is no way to propagate an error out if the stack has overflowed... could it log something ?
Usually once you've overflowed, you can't reliably accomplish anything. This isn't something you should have to actively think about, though, I have a few possible workarounds that I've considered in the past.
on the positive side, i didn't encounter this in real-life code... i was looking for another bug and was getting behaviour which was dependent on some property of Deferreds and chain-length was one possibility i considered - then i just tried long chains to see what happened and noticed that it hung, so it's an artificial problem
Okay, that's good to know, but I want to make sure this isn't something people need to worry about.