Skip to content

common/async: catch all exceptions in call_once() - #71896

Merged
supriti merged 1 commit into
ceph:mainfrom
supriti:wip-call-once-catch-all
Oct 12, 2026
Merged

supriti merged 1 commit into
ceph:mainfrom
supriti:wip-call-once-catch-all

Conversation

@supriti

@supriti supriti commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

do_init() only caught std::exception, so any other exception escaping f() left the once_result in its Wait state without calling wake_all(). Every queued caller will be left waiting. The one exception we must not catch is forced_unwind: boost throws it to unwind a fiber being destroyed and requires by design that it propagate, so rethrow it at once as asio does.

Add tests that throw an int from f(), as rgw's auth engines do.

Fixes: https://tracker.ceph.com/issues/81105

Assisted-by: Claude Opus 5 (1M context) [email protected]

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@cbodley

cbodley commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

can you please raise a tracker issue that explains what the actual problem is? what non-std exception are you seeing here?

@supriti

supriti commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

@cbodley I will create a tracker issue for this and try to add a reproducer.

To be clear, in current main there is no code path that throws a non-std::exception into call_once(). So this is not a live bug today.

I found it while working on https://tracker.ceph.com/issues/67793. My patch routes the keystone auth path through call_once(), and that path reported errors by throwing a bare int. There are 8 such throws in rgw_auth_keystone.cc and 52 across src/rgw. I changed my patch to return the error as a value instead, so it does not hit this.

#71929 does the same thing. Its fetch lambda catches const int and returns tl::unexpected, so it does not hit it either.

But in my understanding, it might be a bug waiting to happen. The docs on call_once() say "if it throws, that exception is rethrown by all calls". For an int that is not what happens. do_init() returns before wake_all(), the state stays in Wait, and every waiter behind that fetch is never woken. There is no error and no log line, and if the once_result lives in a cache that entry stays stuck.

So today it works only because every caller remembers to catch inside the fetch. Compiler won't catch if caller forgets and we get a hang later.

do_init() only caught std::exception, so any other exception escaping f()
left the once_result in its Wait state without calling wake_all(). Every
queued caller will be left waiting. The one exception we must not catch is
forced_unwind: boost throws it to unwind a fiber being destroyed and
requires by design that it propagate, so rethrow it at once as asio does.

Add tests that throw an int from f(), as rgw's auth engines do.

Fixes: https://tracker.ceph.com/issues/81105
Signed-off-by: Supriti Singh <[email protected]>
Assisted-by: Claude Opus 5 (1M context) <[email protected]>
@supriti
supriti force-pushed the wip-call-once-catch-all branch from 740d98c to 30b1dfc Compare September 29, 2026 10:15
@supriti

supriti commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Comment on lines +88 to +89
#if defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
} catch (const boost::context::detail::forced_unwind&) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we really shouldn't depend on library internals that aren't part of their public api

i would prefer to fix code paths that throw non-std exceptions, like the rgw auth paths you pointed out

but approving in the meantime

@supriti

supriti commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@cbodley thanks for approval. I will open a tracker issue to investigate (and change if possible) if rgw code paths can be changed to throw non-std exceptions and add this PR as reference.

Can this PR be merged or does it need to be added to some QA list? I am not aware of the process. Thanks.

@anrao19

anrao19 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by anuchaithra started 2026-10-09-10:05.

@anrao19

anrao19 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by anuchaithra started 2026-10-09-10:05.

pr testing completed and approved by @ivancich, more details in https://tracker.ceph.com/issues/81586.
@supriti , if further is not needed then this can be merged

@supriti
supriti merged commit dcd8835 into ceph:main Oct 12, 2026
23 of 25 checks passed
@github-actions

Copy link
Copy Markdown

This is an automated message by src/script/redmine-upkeep.py.

I have resolved the following tracker ticket due to the merge of this PR:

No backports are pending for the ticket. If this is incorrect, please update the tracker
ticket and reset to Pending Backport state.

Update Log: https://github.com/ceph/ceph/actions/runs/38252600351

@supriti

supriti commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

tracker for fixing code path throwing int https://tracker.ceph.com/issues/81903
Its not a simple find and replace, but I have created tracker so that its not lost.

@cbodley

cbodley commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

thank you!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants