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

Get "Unhandled exception. ROS2.RuntimeError: publisher's context is invalid, at ./src/rcl/publisher.c:389" when I run example more than 20+ minutes. #49

Open
Nickiven opened this issue Apr 14, 2023 · 5 comments

Comments

@Nickiven
Copy link

OS: Ubuntu22.04
ROS2 Humble
.NET 6.0

Hi,
I have modified example "ROSTalker" and "ROSListener" files to implement these two nodes can send and receive data at the same time. Details as below:
image
After build and launch, everything goes well. But 20mintues later, I get an exception as below:
image
Please Help. Thanks.

@Deric-W
Copy link
Contributor

Deric-W commented Apr 14, 2023

Can reproduce this issue on Ubuntu with Ros2 Humble and the talker example, removing the Sleep call speeds the whole process up.

I think it is somehow caused by the garbage collector since removing all calls to Shutdown does not fix this issue while calling GC.TryStartNoGCRegion (or GC.GetGCMemoryInfo, I dont know why) seem to prevent it.

Furthermore, the issue does not occur using the changes in #47, which allocate the structs in native memory.

@Nickiven
Copy link
Author

Can reproduce this issue on Ubuntu with Ros2 Humble and the talker example, removing the Sleep call speeds the whole process up.

I think it is somehow caused by the garbage collector since removing all calls to Shutdown does not fix this issue while calling GC.TryStartNoGCRegion (or GC.GetGCMemoryInfo, I dont know why) seem to prevent it.

Furthermore, the issue does not occur using the changes in #47, which allocate the structs in native memory.

Hi Deric,

According to your suggestion, I revert my changes on listener and talker example. After launching program, it's running smoothly for over 5 hours. It seems that my changes caused the issue, and I don't know why...
Thanks for your responding!

Nick

@Deric-W
Copy link
Contributor

Deric-W commented Apr 17, 2023

Hi,
I was able to reproduce the error with the normal talker example included in this repository, which means the error is not your fault and still present but it seems it is triggered erratically.
I try to find out what exactly is causing it.

@Deric-W
Copy link
Contributor

Deric-W commented Apr 17, 2023

While I am not 100% certain I think it is because of the garbage collector moving the rcl_context_t struct since almost always the error occurs when this happens (on my machine).
The invalid context is not picked up by Ros2cs.Ok() which is probably because after the move the publisher struct contains the old address now pointing to somewhere in memory (for which rcl_context_is_valid is undefined) while the call to rcl_context_is_valid in Ros2cs.Ok() receives the updated one of the still valid context.
Also, it is possible to call Ros2cs.Shutdown() after such a move and keep publishing by removing the shutdown checks in Publisher.Publish and hoping that the old memory location has not been touched since.

@adamdbrw
Copy link
Member

@Nickiven was this issue resolved for you?

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

No branches or pull requests

3 participants