Skip to content

protect access to global logging calls with a mutex#562

Merged
wjwwood merged 2 commits intomasterfrom
wjwwood/fix-logging-thread-safety-issue
Jun 1, 2020
Merged

protect access to global logging calls with a mutex#562
wjwwood merged 2 commits intomasterfrom
wjwwood/fix-logging-thread-safety-issue

Conversation

@wjwwood
Copy link
Copy Markdown
Member

@wjwwood wjwwood commented May 29, 2020

Counter part to ros2/rclcpp#1125

Note this pull request introduces C++ code to the rclpy python library (though it keeps the main files as pure C). I started by trying to implement it without std mutex from C++, but that was taking a lot more time, so I decided to create new C functions to do the mutex locking and call those from the main file. In the future we could reimplement these few functions to be C only if we wanted to do so.

Signed-off-by: William Woodall <william@osrfoundation.org>
@wjwwood wjwwood added the bug Something isn't working label May 29, 2020
@wjwwood wjwwood requested a review from ivanpauno May 29, 2020 02:34
@wjwwood wjwwood self-assigned this May 29, 2020
@wjwwood
Copy link
Copy Markdown
Member Author

wjwwood commented May 29, 2020

CI (full because I couldn't come up with a good way to cover what might be affected without potentially missing something):

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Signed-off-by: William Woodall <william@osrfoundation.org>
@wjwwood
Copy link
Copy Markdown
Member Author

wjwwood commented May 29, 2020

New CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@wjwwood wjwwood requested a review from jacobperron June 1, 2020 17:22
@wjwwood
Copy link
Copy Markdown
Member Author

wjwwood commented Jun 1, 2020

The CI failures are, in my opinion, unrelated. Just waiting on second review from @jacobperron, but I think this is gtg.

@wjwwood wjwwood merged commit 69aad49 into master Jun 1, 2020
@wjwwood wjwwood deleted the wjwwood/fix-logging-thread-safety-issue branch June 1, 2020 17:38
sloretz added a commit that referenced this pull request Mar 11, 2021
Reverts most of #562

ros2/rclcpp#1042 describes a crash that can occur in rclcpp when rcl
logging functions are called in different threads. This was fixed in
ros2/rclcpp#1125, and a similar fix was made for rclpy in #562.

This fix is unnecessary in rclpy because it cannot call the logging
macros from multiple threads unless the GIL is released. The only place
the GIL is released is around rcl_wait(), so the logging methods are
already protected.

Removing this code makes it a little easier to divide the remaining work
of porting _rclpy.c to pybind11. If for some reason we decide to release
the GIL around logging methods in the future, then they can be protected
in the future using `pybind11::call_guard<T>` with a type that locks a
global logging mutex when it is default constructed and unlocks it when
its destructed.

Signed-off-by: Shane Loretz <sloretz@openrobotics.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants