解决RTPS_TRANSPORT_SHM Error

解决以下报错

bash 复制代码
[spawn_entity.py-2] 2026-06-13 14:06:23.338 [RTPS_TRANSPORT_SHM Error] Failed init_port fastrtps_port7419: open_and_lock_file failed -> Function open_port_internal
[spawn_entity.py-2] 2026-06-13 14:06:23.338 [RTPS_TRANSPORT_SHM Error] Failed init_port fastrtps_port7423: open_and_lock_file failed -> Function open_port_internal
[spawn_entity.py-2] 2026-06-13 14:06:23.338 [RTPS_TRANSPORT_SHM Error] Failed init_port fastrtps_port7425: open_and_lock_file failed -> Function open_port_internal
[spawn_entity.py-2] 2026-06-13 14:06:23.338 [RTPS_TRANSPORT_SHM Error] Failed init_port fastrtps_port7427: open_and_lock_file failed -> Function open_port_internal
[spawn_entity.py-2] 2026-06-13 14:06:23.339 [RTPS_TRANSPORT_SHM Error] Failed init_port fastrtps_port7431: open_and_lock_file failed -> Function open_port_internal

这是 ROS 2 FastDDS(FastRTPS)共享内存(SHM)端口冲突/残留 的典型报错,不是 Gazebo 本身的错,是 ROS 2 底层通信层的问题。

一、报错含义

复制代码
Failed init_port fastrtps_port7419: open_and_lock_file failed
  • FastDDS 想用 共享内存文件 /dev/shm/fastrtps_portXXXX 做进程间通信。
  • 但这个文件已经存在、被锁、或权限不够,导致新节点抢不到,直接报错。
  • 常见于:之前没正常退出、多次启动/关闭、Gazebo+ROS2 反复启停。

二、最快解决(直接复制执行)

1)杀干净所有残留 ROS2/Gazebo 进程
bash 复制代码
pkill -9 gazebo gzserver gzclient ros2 rclcpp
pkill -9 fastrtps
2)删除所有残留共享内存文件(关键)
bash 复制代码
rm -f /dev/shm/*fastrtps*

三、根本原因(简单说)

  1. 残留文件没清:上次关仿真时没正常退出,/dev/shm 里留下 fastrtps_port 文件,新进程打不开。
  2. 权限不够:当前用户对 /dev/shm 没有读写权限。
  3. Domain ID 冲突:同一机器多个 ROS2 实例用同一个 ID(默认0),互相抢端口。
  4. FastDDS 版本 bug:特定版本(如 Humble 默认)SHM 稳定性差。

相关推荐
风合星语5 天前
2026 ROS 2 Lyrical C++ 入门(五):Action 实战——任务反馈、取消与超时处理
c++·机器人·ros2·异步编程·lyrical
浅梦语116 天前
32-1 nav2_map_server实际作用与用法图解
ros2·nav2
米糕闯编程7 天前
鱼香ros2(七)功能包组织C++节点
c++·ros2·cmakelists
米糕闯编程8 天前
鱼香ros2(五)用C++编写节点
c++·ros2·cmakelists·鱼香
blueSatchel10 天前
c++action 编写(ros-humble)
c++·ros2
blueSatchel11 天前
ros-humble仿真-建图-导航
linux·ros2
米糕闯编程12 天前
鱼香ros2(三)Linux操作总结
linux·机器人·ros2
蝙蝠侠的小蝙蝠14 天前
【ROS2 工具】Launch
ros2·launch·多节点启动
某林21214 天前
机器人重启失联:DDS 发现机制与传输层静默故障
人工智能·python·机器人·硬件架构·ros2
米糕闯编程15 天前
鱼香ros2(二)运行第一个机器人
机器人·ros2