Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflow with exception handling in futures #93

Closed
drussel opened this issue Oct 2, 2017 · 2 comments
Closed

Stack overflow with exception handling in futures #93

drussel opened this issue Oct 2, 2017 · 2 comments
Milestone

Comments

@drussel
Copy link

drussel commented Oct 2, 2017

Currently, exceptions are handle inline (without creating new promises). This can cause a stack overflow when there are long chains of futures. They could instead be passed off to the executor which appears to help if it is an async one (but I guess the problem would still be there in the case of an immediate executor).

diff --git a/ThirdParty/stlab/concurrency/future.hpp b/ThirdParty/stlab/concurrency/future.hpp
index c0ec59397..d92667fd9 100644
--- a/ThirdParty/stlab/concurrency/future.hpp
+++ b/ThirdParty/stlab/concurrency/future.hpp
@@ -288,7 +288,7 @@ struct shared_base<T, enable_if_copyable<T>> : std::enable_shared_from_this<shar
             _ready = true;
         }
         // propagate exception without scheduling
-        for (const auto& e : then) { e.second(); }
+        for (const auto& e : then) { _executor(e.second); }
     }

     template <typename F, typename... Args>
@@ -456,8 +456,7 @@ struct shared_base<void> : std::enable_shared_from_this<shared_base<void>> {
             then = std::move(_then);
             _ready = true;
         }
-        // propagate exception without scheduling
-        for (const auto& e : then) { e.second(); }
+        for (const auto& e : then) { _executor(e.second); }
     }

     auto get_try() -> bool {
@FelixPetriconi
Copy link
Member

Take over the fix

@FelixPetriconi FelixPetriconi added this to the 1.1 milestone Nov 11, 2017
FelixPetriconi added a commit that referenced this issue Nov 15, 2017
Fix Stack overflow with exception handling in futures #93
@fosterbrereton
Copy link
Member

This issue has been fixed in master as of the 1.1 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants