Skip to content

fix(ex): terminate on an unhandled run_async exception#316

Merged
sgerbino merged 1 commit into
cppalliance:developfrom
sgerbino:fix/run-async-terminate-on-unhandled
Jun 16, 2026
Merged

fix(ex): terminate on an unhandled run_async exception#316
sgerbino merged 1 commit into
cppalliance:developfrom
sgerbino:fix/run-async-terminate-on-unhandled

Conversation

@sgerbino

Copy link
Copy Markdown
Collaborator

Resolves #259.

The run_async trampoline's unhandled_exception swallowed every escaping exception, so an unhandled task error vanished silently and the documented "exceptions are rethrown" behavior never happened.

Make the trampoline call std::terminate instead: an exception reaches it only by escaping a handler (a handler that threw, or the default handler on an otherwise-unhandled task error), which is a genuine fault with no owner to receive it. Failing fast is loud and leak-free (the process ends), and needs no executor cooperation. To observe an error instead, pass an error handler (it receives the exception_ptr); to catch one, co_await the work inside a coroutine.

Cooperative cancellation must not be treated as a fault: the default handler discards a stop_requested_exception (quitter's stop sentinel) so a stopped quitter completes silently rather than terminating. The result-only handler delegates to the same logic.

Document the new behavior and exclude the terminate lines from coverage. Add a POSIX fork-based death test covering both terminate paths (no handler, and a rethrowing handler); it is guarded out on Windows.

The run_async trampoline's unhandled_exception swallowed every escaping
exception, so an unhandled task error vanished silently and the documented
"exceptions are rethrown" behavior never happened.

Make the trampoline call std::terminate instead: an exception reaches it
only by escaping a handler (a handler that threw, or the default handler on
an otherwise-unhandled task error), which is a genuine fault with no owner
to receive it. Failing fast is loud and leak-free (the process ends), and
needs no executor cooperation. To observe an error instead, pass an error
handler (it receives the exception_ptr); to catch one, co_await the work
inside a coroutine.

Cooperative cancellation must not be treated as a fault: the default
handler discards a stop_requested_exception (quitter's stop sentinel) so a
stopped quitter completes silently rather than terminating. The result-only
handler delegates to the same logic.

Document the new behavior and exclude the terminate lines from coverage. Add
a POSIX fork-based death test covering both terminate paths (no handler, and
a rethrowing handler); it is guarded out on Windows.
@cppalliance-bot

Copy link
Copy Markdown

An automated preview of the documentation is available at https://316.capy.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-06-16 13:57:05 UTC

@cppalliance-bot

Copy link
Copy Markdown

GCOVR code coverage report https://316.capy.prtest3.cppalliance.org/gcovr/index.html
LCOV code coverage report https://316.capy.prtest3.cppalliance.org/genhtml/index.html
Coverage Diff Report https://316.capy.prtest3.cppalliance.org/diff-report/index.html

Build time: 2026-06-16 14:14:42 UTC

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.07%. Comparing base (4b27cdd) to head (4b7051d).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #316      +/-   ##
===========================================
- Coverage    98.09%   98.07%   -0.03%     
===========================================
  Files          164      164              
  Lines         8873     8758     -115     
===========================================
- Hits          8704     8589     -115     
  Misses         169      169              
Flag Coverage Δ
linux 98.16% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
include/boost/capy/detail/run_callbacks.hpp 100.00% <100.00%> (ø)
include/boost/capy/ex/run_async.hpp 100.00% <ø> (ø)

... and 6 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4b27cdd...4b7051d. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sgerbino sgerbino merged commit 880619c into cppalliance:develop Jun 16, 2026
38 of 39 checks passed
@sgerbino sgerbino deleted the fix/run-async-terminate-on-unhandled branch June 16, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

run_async behavior when handlers throw

2 participants