manifold icon indicating copy to clipboard operation
manifold copied to clipboard

long chains of Deferred values hang

Open mccraigmccraig opened this issue 9 years ago • 6 comments

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

mccraigmccraig avatar Aug 26 '15 14:08 mccraigmccraig

I think this is due to stack overflows, but I'll look into it.

ztellman avatar Aug 26 '15 16:08 ztellman

that would make sense... should an error not propagate though ?

mccraigmccraig avatar Aug 26 '15 19:08 mccraigmccraig

tho i guess there is no way to propagate an error out if the stack has overflowed... could it log something ?

mccraigmccraig avatar Aug 26 '15 19:08 mccraigmccraig

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.

ztellman avatar Aug 26 '15 19:08 ztellman

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

mccraigmccraig avatar Aug 26 '15 20:08 mccraigmccraig

Okay, that's good to know, but I want to make sure this isn't something people need to worry about.

ztellman avatar Aug 26 '15 23:08 ztellman