Propagate abandoned future errors via future<T>::then()
#13314
Labels
priority: p3
Desirable enhancement or fix. May not be included in next release.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Consider this code:
The expression
F().get()
will throw astd::future_error(std::future_errc::broken_promise)
1:https://en.cppreference.com/w/cpp/thread/promise/%7Epromise
The expression
G().get()
behaves the same way, that all sounds good. Now consider this function:Currently
H().get()
deadlocks. That is not a good thing. I can fix it, the fix is trivial, but unfortunately we have unit tests that depend on the existing behavior.We should fix the tests, unfortunately it is not that easy. These tests (and the code they are testing) needs to work with exceptions disabled (i.e., the
noex
builds aka-fno-exceptions
). With exceptions disabled.get()
terminates the program if the promise was abandoned (or thefuture<T>
contains any exception).So we need to find what
promise
is being destroyed and abandoning the future, and most likely, set the value to some kind ofgoogle::cloud::Status
before destroying the promise.Footnotes
this is the only sensible choice. Once cannot leave
.get()
blocked forever, and there is no validint
value to return. ↩The text was updated successfully, but these errors were encountered: