ROS msgs not received in a topic if publisher starts after subscriber

If I subscribe to a topic before a publisher was registered at that topic, no ROS msgs are received by the subscriber callback once the publisher is registered.

For the sake of simplicity let's call A the machine that is publishing and B the machine that is subscribing to the topic.

If I run 'rostopic echo NAME_OF_TOPIC', I can see that the messages are indeed being published by A. However, the 'subscriber' in B does not seem to be able to receive them if B is run after A.

I came up with a couple of "hacks" to handle the issue. If I set a timeout in B when listening for msgs on a subscriber and either: disconnect/reconnect to RosConnection; or, unsubscribe/resubscribe to the topic; then, the topic is properly subscribed (in B) and receives messages (from A).

However, I've verified that these solutions have the side-effect that publishers in B lose "connection" to their related subscribers in other machines (e.g., in A). I also verified that to unsubscribe/resubscribe to the topic takes a long time (in the order of seconds), which means that messages get lost during that time, and B may not receive a message from A within time, failing the timeout check again.

For completeness, I'm using the following to register a publisher:

ros = ROSConnection.GetOrCreateInstance(); ros.RegisterPublisher<SOME_ROS_MSG>(topicName);

And the following to subscribe to the publisher:

ros = ROSConnection.GetOrCreateInstance();
ros.Subscribe<SOME_ROS_MSG>topicName, CallbackFunction);

I'm following the tutorial presented in the Unity Robotics Hub:

Thanks for the report! I'm responding on your Github issue in order to consolidate discussion on this topic.