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

Switch to custom logging macros to avoid deadlocks #223

Merged
merged 5 commits into from
Jul 1, 2024

Conversation

Yadunund
Copy link
Member

@Yadunund Yadunund commented Jun 29, 2024

Address logging related deadlock discovered in #182.

@clalancette I went with a more C++ implementation here by relying on the popular fmt library which is apparently more performant than printf and ostringstream . Let me know if you prefer following rcutils/logging.h type of implementation with a specifiable allocator. We could also directly invoke rcutils_logging_console_output_handler.

@Yadunund Yadunund requested a review from clalancette June 29, 2024 06:36
@Yadunund Yadunund force-pushed the yadu/fix-logging-deadlock branch from 4223350 to 01cb3ce Compare June 29, 2024 06:43
@Yadunund Yadunund force-pushed the yadu/fix-logging-deadlock branch from 01cb3ce to 85ab442 Compare June 29, 2024 06:47
@clalancette
Copy link
Collaborator

@clalancette I went with a more C++ implementation here by relying on the popular fmt library which is apparently more performant than printf and ostringstream

The problem with bringing in this dependency is that we'll have to deal with it on Windows. Also, in general, the more dependencies this has, the harder it will be to get rmw_zenoh into the core. Finally, my understanding is that either C++-20 or C++-23 will have this directly, so we can get this "for free" when we upgrade in the future. For all of those reasons, I think we should stick with printf-style logging for now.

We could also directly invoke rcutils_logging_console_output_handler.

That's a really good idea, I'd prefer that. While it won't get us all of the features of the rcutils logger, it will at least move us in that direction.

@Yadunund
Copy link
Member Author

Thanks for the quick feedback! I'll update to rely on rcutils functions.

@Yadunund
Copy link
Member Author

Yadunund commented Jul 1, 2024

@clalancette I've updated accordingly.

I've ran the problematic case from #182 several times and it works most of the time*.

# terminal 1
ros2 run rclcpp_components component_container
# terminal 2
for i in {1..100}; do echo "ros2 component load --node-namespace /talker${i} /ComponentManager composition composition::Talker"; done | parallel

* once in a while, the command in terminal 2 does not exit cleanly. However running ros2 node list | wc -l returns 101 indicating that 100 nodes were indeed injected into the component container. All topics are also available. So perhaps the issue there is related to shutdown?

@Yadunund Yadunund force-pushed the yadu/fix-logging-deadlock branch 2 times, most recently from 41a919f to 886b0e6 Compare July 1, 2024 19:31
@Yadunund Yadunund force-pushed the yadu/fix-logging-deadlock branch from 886b0e6 to c20ee54 Compare July 1, 2024 19:35
Copy link
Collaborator

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

Overall, this looks great! I've left a couple of pieces of minor feedback inline.

One other thing we might want to consider is adding a GitHub action here to check if a PR contains RCUTILS_LOG_*, or does #include <rcutils/logging_macros.h>. That would help ensure that we don't add these by accident in the future.

rmw_zenoh_cpp/src/detail/logging.hpp Outdated Show resolved Hide resolved
rmw_zenoh_cpp/src/detail/logging_macros.hpp Outdated Show resolved Hide resolved
@Yadunund Yadunund force-pushed the yadu/fix-logging-deadlock branch from 2ff5d65 to 157f879 Compare July 1, 2024 20:36
Copy link
Collaborator

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

This is fantastic! I'll note that the new check_logging.yaml job is currently failing, because of course this PR does contain RCUTILS_LOG macros (that we are removing). It would be nice if there was a diffDoesNotAdd configuration variable, but after this PR all further ones shouldn't have this problem. So I'm going ahead and approving this.

@Yadunund Yadunund merged commit 011cc79 into rolling Jul 1, 2024
7 of 8 checks passed
@Yadunund Yadunund deleted the yadu/fix-logging-deadlock branch July 1, 2024 20:48
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.

2 participants