Skip to content

Fixing Teleop crash on publish message - #882

Merged
ctw-joao-luis merged 4 commits into
developfrom
bugfix/prevent-teleop-crash-on-publish
Jan 20, 2026
Merged

ctw-joao-luis merged 4 commits into
developfrom
bugfix/prevent-teleop-crash-on-publish

Conversation

@ctw-joao-luis

@ctw-joao-luis ctw-joao-luis commented Jan 9, 2026 •

Copy link
Copy Markdown
Contributor

User-Facing Changes

There were cases when Teleop panel completely crashed Lichtblick because it would try to publish a message faster than topic would be advertised, with this fix this error should not happen again.

Fixes #554

Description

Problem: The publish effect and advertise effect are asynchronous and independent. When a button is clicked, the code attempts to publish a message immediately, but there's a race condition where the topic may not be fully ready yet, causing an unhandled exception that crashes the entire panel.

(I was only able to reproduce the error on Lichtblick's web version on dev mode)

Added try-catch error handling around all context.publish() calls:

So now the try and catch catches the exception instead of letting it crash the component, then setIntreval() retries publishing the message and eventually, even if the publish fails once or twice more, the publish will work because the topic will be finally ready and no more crashes will happen.

HOW TO TEST:

  1. Build and run this image
FROM osrf/ros:humble-desktop

RUN apt-get update && \
    apt-get install -y \
      ros-humble-foxglove-bridge \
      ros-humble-geometry-msgs \
    && rm -rf /var/lib/apt/lists/*

SHELL ["/bin/bash", "-c"]
RUN echo "source /opt/ros/humble/setup.bash" >> /root/.bashrc

EXPOSE 8765

CMD ["bash", "-c", "\
  source /opt/ros/humble/setup.bash && \
  ros2 topic echo /cmd_vel geometry_msgs/msg/Twist & \
  ros2 launch foxglove_bridge foxglove_bridge_launch.xml \
"]

docker build -t lichtblick-teleop-sim .
docker run -it --rm --network host lichtblick-teleop-sim

  1. Open Lichtblick with a websocket connection and connect to port 8765

  2. Use teleop panel and confirm the messages are being published on the terminal the image is running

Checklist

  • The web version was tested and it is running ok
  • The desktop version was tested and it is running ok
  • This change is covered by unit tests
  • Files constants.ts, types.ts and *.style.ts have been checked and relevant code snippets have been relocated

@ctw-joao-luis ctw-joao-luis changed the title adding try and catch to publish() Fixing Teleop crash on publish message Jan 9, 2026
@ctw-joao-luis
ctw-joao-luis marked this pull request as ready for review January 12, 2026 09:50

@rodrigo-p-rodrigues rodrigo-p-rodrigues left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

Note:
Instead of running on host mode, exposing ports worked for me:
docker run --rm -p 8765:8765 lichtblick-teleop-sim

@ctw-joao-luis

Copy link
Copy Markdown
Contributor Author

So I identified the problem, trying to publish a message before advertising, still persisted on first render. Basically unadvertised was being called on the initial render so I implemented an useRef to guarantee that the first render doesnt trigger an unadvertise() call automatically

@ctw-joao-luis

Copy link
Copy Markdown
Contributor Author

Had to make a change on a unit test to actually transcribe what's happening. I discovered why I was only able to reproduce this bug on dev mode. Because of React Strict Mode, the component would get rendered twice making it that:

  1. Component mounts
  2. useLayoutEffect runs → advertise() called
  3. useLayoutEffect cleanup runs → unadvertise() called
  4. useLayoutEffect runs AGAIN → advertise() called again

This was the reason for the bug and why I was not able to reproduce it on Prod.

@sonarqubecloud

Copy link
Copy Markdown

@ctw-joao-luis
ctw-joao-luis requested a review from luluiz January 19, 2026 13:05

@rodrigo-p-rodrigues rodrigo-p-rodrigues left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested it and the issue is fixed, which is an improvement for the users.
I think some of the existing unit tests should be reviewed at some point.

@ctw-joao-luis
ctw-joao-luis merged commit fe082db into develop Jan 20, 2026
18 of 19 checks passed
@ctw-joao-luis
ctw-joao-luis deleted the bugfix/prevent-teleop-crash-on-publish branch January 20, 2026 13:45
@luluiz luluiz mentioned this pull request Apr 23, 2026
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.

TeleopPanel crashes when publishing messages under certain conditions

3 participants