Skip to content

CXX-2723 Explicitly document throwing exception from APM callback is undefined behavior #1015

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

Merged
merged 6 commits into from
Sep 1, 2023

Conversation

eramongodb
Copy link
Contributor

Resolves CXX-2723. Verified by this patch.

Adds explicit documentation in the form of a warning that throwing an exception from an APM callback is undefined behavior. This requirement has always existed but was not properly documented.

As a QoI improvement, despite (now) being explicitly documented as UB, this PR proposes adding noexcept specifiers to the internal APM callback functions (the actual callback that invokes the registered user-provided callback) to reduce the scope of runtime errors should this requirement be violated, as control flow should not have returned from libmongoc via an exception to begin with (the program is already in an invalid state at this point). Any user code that currently violates the nothrow requirement will now terminate via noexcept rather than be allowed to continue with potentially unbounded libmongoc runtime errors. If this is considered too excessive (consider: our own test cases violate this requirement in failure conditions, as Catch2 uses exceptions to report test assertion failures), we can omit the addition of noexcept specifiers.

As a drive-by improvement, ran doxygen -u to update the Doxyfile to address obsolete tag warnings (TCL_SUBST, COLS_IN_ALPHA_INDEX, PERL_PATH, MSCGEN_PATH).

@eramongodb eramongodb self-assigned this Aug 30, 2023
Copy link
Contributor

@vector-of-bool vector-of-bool left a comment

Choose a reason for hiding this comment

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

LGTM


re: Catch2 issues: Only REQUIRE throws exceptions, and looking at the file I would guess that it should be using CHECK() or CHECKED_IF() instead of REQUIRE for every condition.

Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

If this is considered too excessive (consider: our own test cases violate this requirement in failure conditions, as Catch2 uses exceptions to report test assertion failures), we can omit the addition of noexcept specifiers.

I prefer the well defined terminate to undefined behavior.

@eramongodb eramongodb requested a review from kevinAlbs August 31, 2023 20:52
@eramongodb eramongodb requested a review from kevinAlbs September 1, 2023 17:54
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.

3 participants