Add window overload that takes an executor to prevent stack overflow
Summary: AIUI, if there is no executor available, then callbacks are executed inline. `folly::window` uses a recursive helper function (`spawn`) to handle chaining callbacks. So if `window` is used on a large enough collection of `Future`s without executors (e.g., created by `makeFuture`, or have otherwise already completed), you get a stack overflow. A minimal repro looks like: ``` int main(int argc, char** argv) { std::vector<int> v(100000); for(int i=0; i < v.size(); i++) { v[i] = i; } std::vector<folly::Future<folly::Unit>> f = folly::window( std::move(v), [](int /* unused */) { return folly::makeFuture(); }, 1); folly::collectAll(f).get(); } ``` This diff resolves the issue by adding an overload of `folly::window` which takes an executor as its first parameter. The executor-less `window` overload calls through to the new function using an `InlineExecutor` as the default executor. Reviewed By: yfeldblum Differential Revision: D6038733 fbshipit-source-id: 5dcab575592650efa2e106f12632ec06817a0009
Showing
Please register or sign in to comment