From: Tomasz Grabiec <tgra...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: master
input_stream: Fix possible infinite recursion in consume()
It may happen if the consumer is slower than the underlying data
source.
Fixes #195.
Message-Id: <1474545575-26837-1-git-send-email-t...@scylladb.com>
You received this message because you are subscribed to the Google Groups "seastar-dev" group.--
To unsubscribe from this group and stop receiving emails from it, send an email to seastar-dev+unsubscribe@googlegroups.com.
To post to this group, send email to seast...@googlegroups.com.
Visit this group at https://groups.google.com/group/seastar-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/seastar-dev/94eb2c0760f610cf88053d17824f%40google.com.
--
2.5.5
--
You received this message because you are subscribed to the Google Groups "seastar-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seastar-dev+unsubscribe@googlegroups.com.
To post to this group, send email to seast...@googlegroups.com.
Visit this group at https://groups.google.com/group/seastar-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/seastar-dev/1474545575-26837-1-git-send-email-tgrabiec%40scylladb.com.
But when this code is run immediately, then because of the "return" and the compiler could figure out that the code doesn't need any of the on-stack variables, the compiler could do "tail call optimization" to *replace* the last frame, instead of add to it, and avoid recursion. Why doesn't the compiler do it? Is it because C++ destruction order reasons (e.g., C++ thinks it needs to guarantee destruction of objects after then() returns, not before? Or just optimizer limitations?So recursion only happens if fd.get() is ready immediately.So if fd.get() is not ready, we don't have recursion here at all - consume() returns a future immediately, and sometime later will be called again (no recursion).return fd.get().then([] { return consume(); });future<> consume() {That being said, there is something I didn't fully understood here:Sorry about that, guys (Avi actually wrote this code initially, but I overhauled it and should have caught this).I made a note to myself to explain in the Seastar tutorial why recursion is *not* a good replacement for Seastar's iteration primitives (do_until, repeat, etc.).
The code does something like this:
}
Anyway, sure it's better to avoid relying on the tail call optimization...
To unsubscribe from this group and stop receiving emails from it, send an email to seastar-dev...@googlegroups.com.
To post to this group, send email to seast...@googlegroups.com.
Visit this group at https://groups.google.com/group/seastar-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/seastar-dev/CANEVyjuz%3DCn57woeZ57YazEQv%2BBGwKCbCYwjcC0NJnnUcCq8ww%40mail.gmail.com.