Skip to content

Commit

Permalink
future: don't forget to warn about ignored exception
Browse files Browse the repository at this point in the history
When a future is destroyed without handling its exception, we print a
warning message because this is bad programming practice and might hide
an important exception.

However, there is one similar case we don't warn about:

Imagine that a fiber is deliberately started in parallel, by ignoring a
returned future, e.g.,

     future<> f();
     something.then(){ [] {
        // Note we do not "return f()" here, we want it to run in parallel
        f();
     });

Now, if the future returned by f is exceptional, it is ignored, but we
do NOT warn about this. This is because the "future" object is destroyed
immediately (before it becomes exceptional), and what remains is not a
"future" but a "promise", and when that promise is destroyed while is
still exceptional, no warning is printed.

So this patch adds the same warning message we add during future destruction
also to the promise destruction.

Signed-off-by: Nadav Har'El <[email protected]>
  • Loading branch information
nyh authored and avikivity committed Nov 8, 2015
1 parent 6c4144e commit 016cf94
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/future.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,8 @@ void promise<T...>::abandoned() noexcept(move_noexcept) {
assert(_state->available() || !_task);
_future->_local_state = std::move(*_state);
_future->_promise = nullptr;
} else if (_state && _state->failed()) {
report_failed_future(_state->get_exception());
}
}

Expand Down

0 comments on commit 016cf94

Please sign in to comment.