RobotWebTools / rclnodejs

Node.js version of ROS 2.0 client
https://docs.ros.org/en/jazzy/Concepts/Basic/About-Client-Libraries.html#community-maintained
Apache License 2.0
335 stars 72 forks source link

Error with Multiple Nodes Spinning #840

Closed Zaaler closed 2 years ago

Zaaler commented 2 years ago

I have a dispatcher that creates two workers. One worker creates an rclnodsj node and subscribes to a point cloud topic. The other worker also creates a rclnodejs node and subscribes to the same topic. Both workers tell the nodes to spin. The first work starts up correctly and processes a message but, when the second work starts up, the code crashes and I get this error: ` const rtn = exports._reinterpret(buffer, size, offset || 0); ^

Error: reinterpret: Cannot reinterpret from nullptr pointer`

If I run just one of the workers, the code works correctly. Also, if I set isRaw to true, both workers can run without causing eachother to crash.

This might be a problem because I am using a single thread to run multiple nodes. Has anyone tried anything like this? I went down the path of looking into workers and implementing threading but, after I ran both nodes with the isRaw = true and saw they could process the data that way, I backed up.

Steps To Reproduce

  1. Have a dispatcher create two workers.
  2. Have the workers subscribe to the same PointCloud2 topic.
  3. Publish messages to the PointCloud2 topic

Expected Behavior Both nodes are able to receive messages from the topic without crashing.

Actual Behavior The first node that connects crashes when the second node tries to process its callback.

Zaaler commented 2 years ago

I was trying to use multiple nodes in a single thread. I don't think rclnodejs is capable of this.

minggangw commented 2 years ago

Sorry for the delay, yes, we haven't tested with multi-thread scenario, e.g., on different worker threads. Because some rcl functions wrapped by rclnodejs (or nodejs bindings) are not thread-safe, we'd better run in a single thread or you can run on different processes. @Zaaler