You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to reproduce it in the debugger, but I haven't been able to do so thus far. I'll keep trying for that or a core file.
Also, in the debugger I get this, though I don't know if it's related or even in rqt (maybe inside PyQt?):
(lldb) r
Process 19243 launched: '/private/tmp/crystal_testing/source_connext/env/bin/python3' (x86_64)
2018-12-13 16:23:53.683401-0800 python3[19243:20649651] dynamic_cast error 2: One or more of the following type_info's has hidden visibility. They should all have public visibility. N10qt_gui_cpp14PluginProviderE, N11rqt_gui_cpp20RosCppPluginProviderE, N10qt_gui_cpp6PluginE.
rqt_console.console.Console
rqt_msg.messages.Messages
rqt_plot.plot.Plot
rqt_publisher.publisher.Publisher
rqt_py_console.py_console.PyConsole
rqt_service_caller.service_caller.ServiceCaller
rqt_shell.shell.Shell
rqt_srv.services.Services
rqt_top.top_plugin.Top
Process 19243 exited with status = 0 (0x00000000)
Date/Time: 2018-12-13 16:29:29.011 -0800
OS Version: Mac OS X 10.13.6 (17G3025)
Report Version: 12
Bridge OS Version: 3.0 (14Y664)
Anonymous UUID: CD84F906-3490-6767-AF2A-DDD27DF486D0
External Modification Summary:
Calls made by other processes targeting this process:
task_for_pid: 0
thread_create: 0
thread_set_state: 0
Calls made by this process:
task_for_pid: 0
thread_create: 0
thread_set_state: 0
Calls made by all processes on this machine:
task_for_pid: 296111
thread_create: 0
thread_set_state: 3321
VM Region Summary:
ReadOnly portion of Libraries: Total=583.4M resident=0K(0%) swapped_out_or_unallocated=583.4M(100%)
Writable regions: Total=145.1M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=145.1M(100%)
It may be a bug in rclcpp or rclpy that's just being exposed in rqt, or may be something wrong with how rqt is mixing C++ and Python, not sure. I just wanted to get the details down.
I'm not able to reproduce the issue. Sometimes on Mac I run into segfaults on different versions of Python depending on when/where it was built. I'm using the version installed by homebrew.
I'm running 10.13.6. This is the header printed out when running python3
Python 3.7.1 (default, Nov 6 2018, 18:45:35)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
I don't have any reason to believe it has anything to do with the Python version, but instead it's likely due to differences in threading on the two OS's. Though the version of Python may be influencing that as well, I just don't think it's likely myself. Try running stress on your computer at the same time to shake up the scheduling.
The backtrace clearly shows it is failing in Py_Exit, so on Python's shutdown (probably unloading a C++ based library, maybe an atexit() or __del__ in rqt) and then it's destructing the singleton signal handler in librclcpp which is trying to log a message when uninstalling the signal handler, and then fails because logging is already shutdown or something.
The logging failing during the destructor of the signal handler is almost certainly a bug, but it's not the root issue, just an issue while reporting the actual problem.
So it's either a bug in rclcpp (quite possible as that code has recently been changing) or a bug in how rqt is using rclcpp, e.g. maybe it is not doing init/shutdown in the right order or the right number of times or maybe it has something to do with mixing signal handlers up. rclpy and rclcpp may be both are setting up signal handlers and unloading them in different orders, and there there's the Python signal handler... could be messy.
I'll try the stress test, also I may need to make sure all of ros-visualization is built before I test as well. It sounds like it may be the rqt_gui_cpp nodelet_plugin_provider.
What plugins are actually installed on your machine? Do they match the list that's generated? rclcpp is currently only used by rqt_image_view and rqt_gui_cpp. If removing those two packages from your install directory and running --list-plugins doesn't segfault then it's very likely how rqt_gui_cpp creates and destroys the node.
We had to add code into rqt_gui_cpp to create a node and spin it in a separate thread. If rqt isn't using rclcpp correctly, then I would suspect it's in there.
I'm now reproducing the issue. For me, 'sometimes' is about 50% when using --force-discover. Removing rqt_gui_cpp from install resolved the issue. @mlautman looks like this is a threading issue in rqt_gui_cpp, do you have any thoughts?
@wjwwood@brawner It looks like the default spin methods aren't threadsafe. I'm not sure if it is related to this issue, but rqt_gui_cpp definitely needs a similar fix to this: #184. I've been looking into it but I'm at a loss for how we should implement a solution here. While it would be trivial to pass the class encapsulating the executor around and add subscriptions to be destroyed to a queue, this requires that every plugin developer knows to do this. I have been looking through the rviz2 code and it seems they are locking the nodes before adding or removing subscriptions. Is this sufficient? Do you have any other documentation I can reference for this?
It looks like the default spin methods aren't threadsafe.
In which client library?
Also, spin should not be called from multiple threads, it actually doesn't make sense. But I guess you mean not thread-safe with other activities? In rclcpp they should be. I can't say for rclpy off-hand, but I'd recommend coming up with a small example that exihibits the problem, then open an issue on rclcpp/rclpy, at which point we can say if it's a bug or an invalid use case which we should document.
Unfortunately, there's not a lot of documentation for these functions or special cases like these.
I have been looking through the rviz2 code and it seems they are locking the nodes before adding or removing subscriptions.
Please link to the code you're talking about. AFAIK, it should be fine to let subscriptions go out of scope concurrently with spin, and so the locking may be for some other reason.
But I guess you mean not thread-safe with other activities? In rclcpp they should be. I can't say for rclpy off-hand, but I'd recommend coming up with a small example that exihibits the problem
This was an example illustrating this issue with rclpy. rqt_gui_py creates a single node that is shared among python plugins (and similarly rqt_gui_cpp for c++ plugins). If an rqt plugin wants to subscribe to topics, it creates the subscription in its own code and on shutdown destroys it. If node.destroy_subscription() is called while the node is in spin_once, it will crash.
Please link to the code you're talking about. AFAIK, it should be fine to let subscriptions go out of scope concurrently with spin, and so the locking may be for some other reason.
Athough, now that I am looking at it again, maybe spin() is threadsafe? As you mentioned, these methods aren't really documented so any hints here would be great.
Athough, now that I am looking at it again, maybe spin() is threadsafe? As you mentioned, these methods aren't really documented so any hints here would be great.
The design of rclcpp means that "deleting" things like subscriptions and even nodes should be safe to do concurrently with spin functions. This is done by letting the shared pointer to these resources go out of scope. The executor holds a weak pointer to these things and converts those into shared pointers while spinning on them.
Activity
wjwwood commentedon Dec 14, 2018
Adding
--force-discovermakes it more reliable, here's the crash report from macOS:Details
I also got it in
lldb:It may be a bug in rclcpp or rclpy that's just being exposed in rqt, or may be something wrong with how rqt is mixing C++ and Python, not sure. I just wanted to get the details down.
dirk-thomas commentedon Dec 14, 2018
@brawner Can you please try to reproduce the problem? I can't reproduce it on Ubuntu.
brawner commentedon Dec 14, 2018
I'm rebuilding currently, I'll try to reproduce.
For reference,
--list-pluginsis passed through to qt_gui.https://github.com/ros-visualization/qt_gui_core/blob/4b22f7a4a482565c94399c0f704b0612f61bec5a/qt_gui/src/qt_gui/main.py#L497
If it prints out a list though, then the segfault is happening on exit.
rqt/rqt_gui/src/rqt_gui/main.py
Line 87 in 31af4cf
brawner commentedon Dec 14, 2018
I'm not able to reproduce the issue. Sometimes on Mac I run into segfaults on different versions of Python depending on when/where it was built. I'm using the version installed by homebrew.
I'm running 10.13.6. This is the header printed out when running
python3wjwwood commentedon Dec 14, 2018
I don't have any reason to believe it has anything to do with the Python version, but instead it's likely due to differences in threading on the two OS's. Though the version of Python may be influencing that as well, I just don't think it's likely myself. Try running stress on your computer at the same time to shake up the scheduling.
The backtrace clearly shows it is failing in
Py_Exit, so on Python's shutdown (probably unloading a C++ based library, maybe anatexit()or__del__in rqt) and then it's destructing the singleton signal handler inlibrclcppwhich is trying to log a message when uninstalling the signal handler, and then fails because logging is already shutdown or something.The logging failing during the destructor of the signal handler is almost certainly a bug, but it's not the root issue, just an issue while reporting the actual problem.
So it's either a bug in rclcpp (quite possible as that code has recently been changing) or a bug in how rqt is using rclcpp, e.g. maybe it is not doing init/shutdown in the right order or the right number of times or maybe it has something to do with mixing signal handlers up. rclpy and rclcpp may be both are setting up signal handlers and unloading them in different orders, and there there's the Python signal handler... could be messy.
brawner commentedon Dec 14, 2018
I'll try the stress test, also I may need to make sure all of ros-visualization is built before I test as well. It sounds like it may be the rqt_gui_cpp nodelet_plugin_provider.
What plugins are actually installed on your machine? Do they match the list that's generated?
rclcppis currently only used byrqt_image_viewandrqt_gui_cpp. If removing those two packages from your install directory and running--list-pluginsdoesn't segfault then it's very likely how rqt_gui_cpp creates and destroys the node.We had to add code into rqt_gui_cpp to create a node and spin it in a separate thread. If rqt isn't using rclcpp correctly, then I would suspect it's in there.
Does this destructor look right?
rqt/rqt_gui_cpp/src/rqt_gui_cpp/nodelet_plugin_provider.cpp
Lines 51 to 55 in 31af4cf
brawner commentedon Dec 14, 2018
I'm now reproducing the issue. For me, 'sometimes' is about 50% when using
--force-discover. Removingrqt_gui_cppfrom install resolved the issue. @mlautman looks like this is a threading issue in rqt_gui_cpp, do you have any thoughts?wjwwood commentedon Dec 14, 2018
@brawner I don't have cycles to look at it right now, but I can at some point.
mlautman commentedon Dec 19, 2018
@wjwwood @brawner It looks like the default spin methods aren't threadsafe. I'm not sure if it is related to this issue, but rqt_gui_cpp definitely needs a similar fix to this: #184. I've been looking into it but I'm at a loss for how we should implement a solution here. While it would be trivial to pass the class encapsulating the executor around and add subscriptions to be destroyed to a queue, this requires that every plugin developer knows to do this. I have been looking through the rviz2 code and it seems they are locking the nodes before adding or removing subscriptions. Is this sufficient? Do you have any other documentation I can reference for this?
wjwwood commentedon Dec 19, 2018
In which client library?
Also, spin should not be called from multiple threads, it actually doesn't make sense. But I guess you mean not thread-safe with other activities? In
rclcppthey should be. I can't say forrclpyoff-hand, but I'd recommend coming up with a small example that exihibits the problem, then open an issue onrclcpp/rclpy, at which point we can say if it's a bug or an invalid use case which we should document.Unfortunately, there's not a lot of documentation for these functions or special cases like these.
Please link to the code you're talking about. AFAIK, it should be fine to let subscriptions go out of scope concurrently with spin, and so the locking may be for some other reason.
brawner commentedon Dec 19, 2018
@wjwwood Here is an example with rclpy. You can't destroy a subscription from a separate thread while a node is spinning.
#181
Proposed PR that addresses the issue #184
wjwwood commentedon Dec 19, 2018
Where is the example? I don't see one in either the issue #181 or the pr #184.
brawner commentedon Dec 19, 2018
This was an example illustrating this issue with rclpy. rqt_gui_py creates a single node that is shared among python plugins (and similarly rqt_gui_cpp for c++ plugins). If an rqt plugin wants to subscribe to topics, it creates the subscription in its own code and on shutdown destroys it. If
node.destroy_subscription()is called while the node is in spin_once, it will crash.wjwwood commentedon Dec 19, 2018
Sorry, I was looking for a trivial python script that exposes the issue. Without a trivial example, it's hard to rule out some other influence related to the architecture of
rqt. (something like this: http://sscce.org/)brawner commentedon Dec 19, 2018
@wjwwood follow up here ros2/rclpy#255
mlautman commentedon Dec 20, 2018
RViz2 creates a wrapper around the node it passes into each of the plugins
https://github.com/ros2/rviz/blob/ros2/rviz_common/include/rviz_common/ros_integration/ros_node_abstraction.hpp
These plugins then lock the node before calling methods on the underlying node.
https://github.com/ros2/rviz/blob/0c7145448b4bd47a022fa8957d6c25bfcf07174a/rviz_default_plugins/src/rviz_default_plugins/displays/camera/camera_display.cpp#L283
I think this is what made me think that
spin()might not be threadsafe.https://github.com/ros2/rclcpp/blob/69d7e69957a63487e07db01831082a8adcd14968/rclcpp/include/rclcpp/executor.hpp#L194
Athough, now that I am looking at it again, maybe
spin()is threadsafe? As you mentioned, these methods aren't really documented so any hints here would be great.wjwwood commentedon Dec 20, 2018
All of the spin like functions should be run mutually exclusively.
Spin like functions should be thread-safe in that it will fail if you call it from two different threads, e.g.
spin_once()will fail if you call it concurrently: https://github.com/ros2/rclcpp/blob/eb2081bb25867da932a6c09b7729aced4f5f182e/rclcpp/src/rclcpp/executor.cpp#L237The design of
rclcppmeans that "deleting" things like subscriptions and even nodes should be safe to do concurrently with spin functions. This is done by letting the shared pointer to these resources go out of scope. The executor holds a weak pointer to these things and converts those into shared pointers while spinning on them.dirk-thomas commentedon Jul 29, 2019
Assuming this has been resolved by ros2/rclpy#318 I am closing the ticket.