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

NuDBBackend destructor should not throw #4017

Closed
wants to merge 1 commit into from

Conversation

scottschurr
Copy link
Collaborator

High Level Overview of Change

The NuDBBackend destructor currently may throw an exception. Most C++ folks agree that throwing an exception from a destructor is a bad idea:

https://isocpp.org/wiki/faq/exceptions#dtors-shouldnt-throw

The modified code logs the problem that NuDB is complaining about at fatal level, so it is very likely to get into the log. Then it swallows the exception so the exception does not propagate out of the body of the destructor.

Context of Change

There's been an unresolved sporadic crash only in certain testing scenarios where NuDBBackend might be implicated. While examining the code I noticed that the NuDBBacked destructor could throw. So I'm patching that up and and improving the logging regarding what NuDB might be complaining about.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

There should be no behavior change as a result of this pull request. There's no reason to mention it in the release notes.

@@ -174,10 +183,20 @@ class NuDBBackend : public Backend
nudb::error_code ec;
db_.close(ec);
if (ec)
{
// Log to make sure the nature of the error gets to the user.
JLOG(j_.fatal()) << "NuBD close() failed: " << ec.message();
Throw<nudb::system_error>(ec);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the error is getting logged, and the nearest catch block doesn't do anything with this error, what's the reason for still throwing? If we get rid of it seems like we could also eliminate the try/catch block in the destructor. This would also match the approach being used for the following call to remove_all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason I left the throw was so behavior is unchanged for any calls to close() other than the one from the destructor. I did not audit all calls to close(), but I assumed there were some because close() is a public method of Backend. Note the comment in Backend.cpp:

    /** Close the backend.
        This allows the caller to catch exceptions.
    */
    virtual void
    close() = 0;

Copy link
Contributor

Choose a reason for hiding this comment

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

We would need to prove that no other client of close() is depending on the exception. This isn't impossible, but is a little tricky considering this is a public virtual.

Copy link
Contributor

Choose a reason for hiding this comment

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

Preserving the existing throw sounds good

@scottschurr scottschurr added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Dec 8, 2021
@scottschurr
Copy link
Collaborator Author

The CI failures are all known issues on macOS. So it looks like this code has survived as much of CI as possible at the moment. I'm marking the pull request passed.

This was referenced Dec 15, 2021
@scottschurr scottschurr deleted the no-dtor-exception branch December 17, 2021 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants