question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Port #426 Autobahn WebSocket server from ros1 to ros2

See original GitHub issue

Description

The issue described in https://github.com/RobotWebTools/rosbridge_suite/issues/425 and fixed in https://github.com/RobotWebTools/rosbridge_suite/pull/426 still persists in ros2 because the fix was not ported to ros2. There was a request made in https://github.com/RobotWebTools/rosbridge_suite/pull/426#issuecomment-532471720 but I do not see any issue tracking the progress of porting the changes to ros2.

  • Library Version: 1.1.2-1focal.20220126.193440
  • ROS Version: Rolling
  • Platform / OS: Ubuntu 20.04

Steps To Reproduce

I can reproduce issues by performing rapid connect/disconnect while topics are actively being published. I launch the websocket server while other nodes are publishing. Then I have a browser web page that opens a websocket connection and subscribes to topics using https://github.com/RobotWebTools/roslibjs. I can refresh the page rapidly a few times and then observe the websocket server print errors and then no longer accept new websocket connections.

Expected Behavior

The server should recover from websocket disconnect errors mid-write without locking the entire websocket server.

Actual Behavior

The server becomes locked due to the _write_lock never being released because of exception handling logic in the prewrite_message method.

Here is an example trace of the exception:

ERROR:tornado.application:Exception in callback functools.partial(<function wrap.<locals>.null_wrapper at 0x7f75d8f4d700>, <Future finished exception=WebSocketClosedError()>)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/tornado/websocket.py", line 867, in write_message
    fut = self._write_frame(True, opcode, message, flags=flags)
  File "/usr/lib/python3/dist-packages/tornado/websocket.py", line 846, in _write_frame
    return self.stream.write(frame)
  File "/usr/lib/python3/dist-packages/tornado/iostream.py", line 570, in write
    self._check_closed()
  File "/usr/lib/python3/dist-packages/tornado/iostream.py", line 1112, in _check_closed
    raise StreamClosedError(real_error=self.error)
tornado.iostream.StreamClosedError: Stream is closed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/tornado/ioloop.py", line 758, in _run_callback
    ret = callback()
  File "/usr/lib/python3/dist-packages/tornado/stack_context.py", line 300, in null_wrapper
    return fn(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/tornado/ioloop.py", line 779, in _discard_future_result
    future.result()
  File "/usr/lib/python3/dist-packages/tornado/gen.py", line 326, in wrapper
    yielded = next(result)
  File "/opt/colcon_ws/install/rosbridge_server/lib/python3.8/site-packages/rosbridge_server/websocket_handler.py", line 197, in prewrite_message
    future = self.write_message(message, binary)
  File "/usr/lib/python3/dist-packages/tornado/websocket.py", line 262, in write_message
    return self.ws_connection.write_message(message, binary=binary)
  File "/usr/lib/python3/dist-packages/tornado/websocket.py", line 869, in write_message
    raise WebSocketClosedError()
tornado.websocket.WebSocketClosedError
ERROR:tornado.application:Exception in callback functools.partial(<function wrap.<locals>.null_wrapper at 0x7f75d8f2d0d0>, <Future finished exception=WebSocketClosedError()>)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/tornado/ioloop.py", line 758, in _run_callback
    ret = callback()
  File "/usr/lib/python3/dist-packages/tornado/stack_context.py", line 300, in null_wrapper
    return fn(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/tornado/ioloop.py", line 779, in _discard_future_result
    future.result()
  File "/usr/lib/python3/dist-packages/tornado/gen.py", line 326, in wrapper
    yielded = next(result)
  File "/opt/colcon_ws/install/rosbridge_server/lib/python3.8/site-packages/rosbridge_server/websocket_handler.py", line 197, in prewrite_message
    future = self.write_message(message, binary)
  File "/usr/lib/python3/dist-packages/tornado/websocket.py", line 259, in write_message
    raise WebSocketClosedError()
tornado.websocket.WebSocketClosedError

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
v-kinivcommented, Dec 3, 2022

I tried unsuccessfully to get Rosbridge to work stable with ROS2, and ended up writing bridge in C++, it’s ROS2 only (tested on Galactic): https://github.com/v-kiniv/rws

Give it a try if you have problems with Rosbridge and ROS2.

p.s. Sorry for the off-topic comment, but I think it might useful for others who will came here looking for a solution for the Rosbridge+ROS2 issues.

1reaction
achim-kcommented, Oct 5, 2022

I think it makes sense to get #741 in first, before trying to migrate to autobahn. I will look into that

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSocket Programming - Autobahn|Python - Read the Docs
This guide introduces WebSocket programming with Autobahn. You'll see how to create WebSocket server (“Creating Servers”) and client applications (“Creating ...
Read more >
Bountysource
Port #426 Autobahn WebSocket server from ros1 to ros2.
Read more >
Packages - rosbridge_server - ROS Index
The server now allows choosing port:=0 to select an ephemeral port, ... Add cbor-raw compression support (#574, adapted from ROS 1 implementation #452)....
Read more >
ROS 1 - Docs - Foxglove Studio
Connect directly to your running ROS stack via WebSockets using a Rosbridge connection. This connection option requires only a single open port between...
Read more >
sources_in_unstable_but_not_in... - UDD - Debian
... 52990 simple-scan 52879 evolution-data-server 52849 gnome-control-center ... lib3ds 1254 debian-ports-archive-keyring 1253 ruby-mail 1253 fonts-nanum ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found