Skip to content

Remove destructor logging #424

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lia-viam
Copy link
Contributor

So this came up while working on another PR, but it turns out logging in destructors was causing issues after all. In particular the RobotClient destructor may run after Instance (and hence LogManager) have already been destroyed. I encountered this when joining threads in RobotClient::close was throwing an exception due to joining an unjoinable thread, so that will probably need a separate hotfix, but we should merge this one soon.

@lia-viam lia-viam requested a review from a team as a code owner April 24, 2025 20:39
@lia-viam lia-viam requested review from njooma and stuqdog and removed request for a team April 24, 2025 20:39
@@ -150,6 +150,8 @@ BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE(attr_time,
/// @ingroup Log
///
/// Use this macro to generate log messages pertaining to the SDK at large.
/// @warning Using this macro outside of the lifetime of LogManager is UB and for this reason
/// logging in destructors should be done with caution or avoided entirely.
Copy link
Member

Choose a reason for hiding this comment

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

So, if the rule is that an Instance must outlive ModuleService or RobotClient, how can this situation arise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just encountered this when trying to run example_dial_api_key to do direct dialing, which was failing locally for me. After failing to list the resources, thread::join in close was throwing a resource_deadlock_would_occur (i.e., attempted to join current thread) and then logging that exception in ~RobotClient was causing a null pointer deref in Boost.Log, at which point a print statement confirmed that instance had been destructed before the dtor was called.

Now as for how this happens I'm not so sure honestly. I would expect C++ objects to be destroyed in the reverse order that they're created, which means Instance should be first in last out, but it seemed like that's not what was happening

Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

Abstractly this all looks reasonable. It does seem strange that the logging is being called after the instance is destroyed; if that could be resolved that seems like a preferable solution? But if not this looks good to me.

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