Skip to content

Fix SIGSEGV on ROS 2 Rolling caused by rosidl sequence ABI change#1480

Merged
minggangw merged 4 commits intoRobotWebTools:developfrom
minggangw:fix-rolling-crash-caused-rosidl-abi-change
Apr 8, 2026
Merged

Fix SIGSEGV on ROS 2 Rolling caused by rosidl sequence ABI change#1480
minggangw merged 4 commits intoRobotWebTools:developfrom
minggangw:fix-rolling-crash-caused-rosidl-abi-change

Conversation

@minggangw
Copy link
Copy Markdown
Member

@minggangw minggangw commented Apr 8, 2026

ROS 2 Rolling merged ros2/rosidl#941 and ros2/rosidl#942 as part of the native buffer feature. The ROSIDL_RUNTIME_C__PRIMITIVE_SEQUENCE macro now emits two extra boolean fields (is_rosidl_buffer, owns_rosidl_buffer) in every primitive sequence struct, growing them from 24 to 32 bytes. Non-primitive sequences (e.g. Parameter__Sequence) are unchanged at 24 bytes.

The rclnodejs code generator produces ref-struct-di definitions for these sequence types. Because the generated layout lacked the new fields, every message containing a primitive sequence had misaligned field offsets when serialized, causing Fast DDS to segfault in get_serialized_size_* during rcl_publish.

Changes:

  1. rosidl_gen/templates/message-template.js — Detect Rolling+ at generation time via DistroUtils.getDistroId() and compute needsRosidlBufferFields once per message. Conditionally emit is_rosidl_buffer and owns_rosidl_buffer in the generated sequence struct only for primitive-package types (Bool, Byte, Int8, …, Float64, String) on Rolling+. Generated files get clean, static struct definitions with no runtime require() or ternary.

  2. .github/workflows/linux-x64-build-and-test.yml — Add rosidl_buffer_py and pybind11 to rosdep --skip-keys for the Rolling nightly install, since these new packages from the native buffer feature have unresolvable rosdep keys in the tarball context.

Verified: Rolling: test-parameters (33), test-parameter-service (9), test-action-client (19) — all pass. Jazzy: test-parameters (33), test-parameter-service (9), test-action-client (18+1 pending) — all pass.

Fix: #1481

Copilot AI review requested due to automatic review settings April 8, 2026 03:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the JS message code generator template to account for a ROS 2 Rolling rosidl sequence ABI change that can otherwise cause memory layout mismatches (and SIGSEGV) when handling primitive sequences.

Changes:

  • Extends the generated RefStructArray (sequence) struct for primitive base types with two additional boolean fields on ROS 2 Rolling and later.
  • Adds a runtime ROS distro check in the generated message modules to conditionally include these fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +352 to +355
isPrimitivePackage(spec.baseType)
? ` ...require('../../lib/distro.js').getDistroId() >= require('../../lib/distro.js').getDistroId('rolling')
? { is_rosidl_buffer: ref.types.bool, owns_rosidl_buffer: ref.types.bool }
: {}`
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

The generated code inlines require('../../lib/distro.js') twice inside an object spread/ternary. Since this runs in every generated message module, it’s more maintainable (and slightly cheaper) to require the module once (e.g., const DistroUtils = ...) and compare against DistroUtils.DistroId.ROLLING (or a single getDistroId('rolling')) rather than repeating the call in the expression.

Copilot uses AI. Check for mistakes.
Comment on lines +351 to +356
${
isPrimitivePackage(spec.baseType)
? ` ...require('../../lib/distro.js').getDistroId() >= require('../../lib/distro.js').getDistroId('rolling')
? { is_rosidl_buffer: ref.types.bool, owns_rosidl_buffer: ref.types.bool }
: {}`
: ''
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

This change gates struct layout on the runtime distro. Please add a regression test that validates the generated output for a primitive sequence includes is_rosidl_buffer/owns_rosidl_buffer when ROS_DISTRO=rolling (and omits them for earlier distros), so future template edits don’t silently reintroduce the Rolling ABI mismatch.

Copilot uses AI. Check for mistakes.
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 8, 2026

Coverage Status

coverage: 85.411%. remained the same — minggangw:fix-rolling-crash-caused-rosidl-abi-change into RobotWebTools:develop

@minggangw minggangw merged commit 01847d5 into RobotWebTools:develop Apr 8, 2026
16 checks passed
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

Successfully merging this pull request may close these issues.

Fix SIGSEGV on ROS 2 Rolling

3 participants