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

[Foxy] Handle exception on deserializing ROS message #603

Merged
merged 4 commits into from
Jun 3, 2022
Merged

[Foxy] Handle exception on deserializing ROS message #603

merged 4 commits into from
Jun 3, 2022

Conversation

suurjaak
Copy link

Fixes ros2/rclpy#923.

Minimal code for reproducing error:

import rclpy.serialization, std_msgs.msg
rclpy.serialization.deserialize_message(b"", std_msgs.msg.String)

Result without the fix:

user@host:~$ python3
Python 3.8.10 (default, Sep 28 2021, 16:10:42) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rclpy.serialization, std_msgs.msg
>>> rclpy.serialization.deserialize_message(b"", std_msgs.msg.String)
terminate called after throwing an instance of 'eprosima::fastcdr::exception::NotEnoughMemoryException'
  what():  Not enough memory in the buffer stream
Aborted (core dumped)
user@host:~$

Result with the fix:

user@host:~$ python3
Python 3.8.10 (default, Sep 28 2021, 16:10:42) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rclpy.serialization, std_msgs.msg
>>> rclpy.serialization.deserialize_message(b"", std_msgs.msg.String)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/serialization.py", line 42, in deserialize_message
    return _rclpy.rclpy_deserialize(serialized_message, message_type)
_rclpy.RCLError: Failed to deserialize ROS message
>>>

Signed-off-by: Erki Suurjaak <erki@lap.ee>
Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suurjaak i just noticed that we could do backport this?

@suurjaak
Copy link
Author

@suurjaak i just noticed that we could do backport this?

Indeed, that looks fully compatible, and more complete.

And looking it over, I noticed a few more things I would change, to make deserialization more robust. The dynamic_cpp version can throw std::runtime_error which would also crash and terminate the process, I believe.

How should I go about this - cherry-pick commits from that pull request into this one?

@fujitatomoya
Copy link
Collaborator

How should I go about this - cherry-pick commits from that pull request into this one?

#505 has been merged to master, humble and galactic. So yes, you can cherry-pick the PR.

The dynamic_cpp version can throw std::runtime_error which would also crash and terminate the process, I believe.

#505 seems to address this too. If you have additional fix related, i would create another PR to master then backport it to humble, galactic and foxy.

@suurjaak
Copy link
Author

The dynamic_cpp version can throw std::runtime_error which would also crash and terminate the process, I believe.

#505 seems to address this too. If you have additional fix related, i would create another PR to master then backport it to humble, galactic and foxy.

As an example, deserializeROSMessage(Cdr&, void*, void*) calls the overloaded deserializeROSMessage(Cdr&, MembersType*, void*), and the latter throws runtime_error on a number of conditions. But the former only catches fastcdr exceptions.

Does this not look equally crash-inducing? rclpy should not just terminate upon receiving invalid data.

@fujitatomoya
Copy link
Collaborator

#505 addresses CDR exception, which i think we can fix original issue for foxy ros2/rclpy#923.

As an example, deserializeROSMessage(Cdr&, void*, void*) calls the overloaded deserializeROSMessage(Cdr&, MembersType*, void*), and the latter throws runtime_error on a number of conditions. But the former only catches fastcdr exceptions.

i am not sure if we can make this happen, but as you pointed out this possibly generates the std::runtime_error.

MiguelCompany and others added 3 commits May 14, 2022 20:17
* Capturing fastcdr exceptions.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
Signed-off-by: Erki Suurjaak <erki@lap.ee>
Signed-off-by: Erki Suurjaak <erki@lap.ee>
@suurjaak
Copy link
Author

Added #505.

i am not sure if we can make this happen, but as you pointed out this possibly generates the std::runtime_error.

Can you clarify this comment? I am not sure what you meant here.

@fujitatomoya
Copy link
Collaborator

i mean i am not sure if we can make it happen. if you are willing to address this, i am happy to review PR too !!! in that case, probably we would want to have another PR, so that we can have individual PR for each problem.

@suurjaak
Copy link
Author

Regarding making another pull request - there appears no need, as the current ROS2 master no longer terminates rclpy on a C++ exception, but provides a catchable exception in Python instead.
At least that was the behavior when I ran tests on a locally-built master.

@fujitatomoya
Copy link
Collaborator

CI:

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

@fujitatomoya
Copy link
Collaborator

@MiguelCompany @ivanpauno requesting another review.

@suurjaak
Copy link
Author

@fujitatomoya Is there a problem on the buildfarm?

Package 'rmw_fastrtps_dynamic_cpp' specified with --packages-above-and-dependencies was not found

@MiguelCompany
Copy link
Contributor

Package 'rmw_fastrtps_dynamic_cpp' specified with --packages-above-and-dependencies was not found

I think the reason for this is that the CI was launched with use_fastrtps_dynamic: false, and that puts a COLCON_IGNORE on rmw_fastrtps_dynamic_cpp

Copy link
Contributor

@MiguelCompany MiguelCompany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@fujitatomoya
Copy link
Collaborator

CI(retry)

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

@fujitatomoya
Copy link
Collaborator

fujitatomoya commented May 19, 2022

windows warnings and errors are unrelated, just in case retry.

  • Windows Build Status

@clalancette clalancette added this to Proposed in Foxy Patch Release 8 via automation Jun 2, 2022
@fujitatomoya
Copy link
Collaborator

CI: (only CI_USE_FASTRTPS_STATIC)

  • Windows Build Status

@fujitatomoya
Copy link
Collaborator

wrong operation, retry CI: (only CI_USE_FASTRTPS_STATIC)

  • Windows Build Status

@fujitatomoya
Copy link
Collaborator

@clalancette do we need to run CI_USE_FASTRTPS_DYNAMIC? by default, CI does not run this one.

@fujitatomoya
Copy link
Collaborator

@suurjaak

could you check test failures https://ci.ros2.org/job/ci_windows/17188/testReport/? it seems to be unrelated, but just in case.

https://ci.ros2.org/job/ci_windows/17188/cmake/folder.114148/ and https://ci.ros2.org/job/ci_windows/17188/msbuild/new/ are unrelated for sure.

@suurjaak
Copy link
Author

suurjaak commented Jun 3, 2022

@fujitatomoya anything specific from those 79 failures? I looked over a few dozen items and they all seemed unrelated.

@fujitatomoya
Copy link
Collaborator

I checked everything, but none of them seems to be related.

I want to be sure on this before merge, see if foxy master CI has the same unstable problem.

CI (foxy original):

  • Windows Build Status

@fujitatomoya
Copy link
Collaborator

Okay now mainline(foxy branch) has the same unstable result. I will go ahead to merge this into foxy.

@fujitatomoya fujitatomoya merged commit 1527f09 into ros2:foxy Jun 3, 2022
@jacobperron jacobperron moved this from Proposed to Needs release in Foxy Patch Release 8 Jul 22, 2022
@jacobperron jacobperron moved this from Needs release to Done in Foxy Patch Release 8 Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants