Skip to content
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

Don't throw exceptions from ~_single_instance_hook #2514

Merged
merged 2 commits into from
May 25, 2023

Conversation

Alan-Jowett
Copy link
Member

Resolves: #2511

Description

C++ destructors are noexcept by definition. Throwing from a destructor is a noexcept violation which results in abort. Avoid this by making best effort to cleanup in destructors.

Testing

CI/CD

Documentation

No.

Signed-off-by: Alan Jowett <[email protected]>
@codecov
Copy link

codecov bot commented May 24, 2023

Codecov Report

Merging #2514 (fa4deee) into main (667a948) will decrease coverage by 0.12%.
The diff coverage is 33.33%.

@@            Coverage Diff             @@
##             main    #2514      +/-   ##
==========================================
- Coverage   84.06%   83.95%   -0.12%     
==========================================
  Files         155      155              
  Lines       28847    28849       +2     
==========================================
- Hits        24251    24219      -32     
- Misses       4596     4630      +34     
Impacted Files Coverage Δ
tests/end_to_end/helpers.h 89.75% <33.33%> (-1.57%) ⬇️

... and 10 files with indirect coverage changes

detach();
// Best effort cleanup. Ignore errors.
if (link_object) {
(void)ebpf_link_detach(link_object);
Copy link
Contributor

Choose a reason for hiding this comment

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

Though unrelated to changes in this PR, it looks like detach() has a bug: It is throwing an exception when ebpf_link_detach() returns EBPF_SUCCESS.

    detach()
    {
        if (link_object != nullptr) {
            if (ebpf_link_detach(link_object) == EBPF_SUCCESS) {
                throw std::runtime_error("ebpf_link_detach failed");
            }
            ebpf_link_close(link_object);
            link_object = nullptr;
        }
    }

@Alan-Jowett Alan-Jowett added this pull request to the merge queue May 25, 2023
Merged via the queue into microsoft:main with commit 904608d May 25, 2023
@Alan-Jowett Alan-Jowett deleted the issue2511 branch May 25, 2023 19:33
@Alan-Jowett Alan-Jowett restored the issue2511 branch June 1, 2023 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

noexcept violation - unit_tests!_single_instance_hook::~_single_instance_hook throws exception
4 participants