Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Unreleased

**Fixed**

* Fixed reconnection on the Twisted transport failing after a connection had
been idle for more than a few seconds: ``connect`` now schedules the
connection through the reactor thread so an idle reactor is woken to service
it (previously the new connector was added from another thread and the
reactor, blocked in ``select()``, never noticed it).

**Deprecated**

**Removed**
Expand Down
10 changes: 10 additions & 0 deletions src/roslibpy/comm/comm_autobahn.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ def __init__(self, *args, **kwargs):

def connect(self):
"""Establish WebSocket connection to the ROS server defined for this factory."""
# Route the connection setup through the reactor thread. Calling
# ``connectWS`` directly only happens to work while the reactor is busy;
# once it is idle (e.g. more than ``closeHandshakeTimeout`` seconds after
# a previous disconnect) it sits blocked in ``select()`` and never
# notices a connector added from another thread, so the connection times
# out. ``callFromThread`` wakes it, and is also safe before the reactor
# has started (the call is queued and runs once it does).
reactor.callFromThread(self._connect)

def _connect(self):
self.connector = connectWS(self)

@property
Expand Down
Loading