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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/ripple/nodestore/backend/NuDBFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ class NuDBBackend : public Backend

~NuDBBackend() override
{
close();
try
{
// close can throw and we don't want the destructor to throw.
close();
}
catch (nudb::system_error const&)
{
// Don't allow exceptions to propagate out of destructors.
// close() has already logged the error.
}
}

std::string
Expand Down Expand Up @@ -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

}

if (deletePath_)
{
boost::filesystem::remove_all(name_);
boost::filesystem::remove_all(name_, ec);
if (ec)
{
JLOG(j_.fatal()) << "Filesystem remove_all of " << name_
<< " failed with: " << ec.message();
}
}
}
}
Expand Down