Skip to content

Bring back re-connect logic#58

Open
jprestwo wants to merge 1 commit into
locus-noetic-develfrom
rospy-subscriber-fix
Open

Bring back re-connect logic#58
jprestwo wants to merge 1 commit into
locus-noetic-develfrom
rospy-subscriber-fix

Conversation

@jprestwo

@jprestwo jprestwo commented Jun 8, 2026

Copy link
Copy Markdown

This brings back the reconnect logic to fix an issue where a subscriber TCP connection dies. Since the current logic never tries to reconnect (and instead relies on publisherUpdate) this leaves subscribers in a dead state if their TCP connection goes down.

The original fix was intended to improve the speed at which subscribers re-establish the connection by bailing out with no retries and relying on publisherUpdate to trigger a reconnect. This only works if the publisher goes down, but if the roles are flipped and the subscribers TCP connection dies the subscriber is left unconnected indefinitely.

This brings back the reconnect logic to fix an issue where a
subscriber TCP connection dies. Since the current logic never tries
to reconnect (and instead relies on publisherUpdate) this leaves
subscribers in a dead state if their TCP connection goes down.

The original fix was intended to improve the speed at which
subscribers re-establish the connection by bailing out with no
retries and relying on publisherUpdate to trigger a reconnect. This
only works if the publisher goes down, but if the roles are flipped
and the subscribers TCP connection dies the subscriber is left
unconnected indefinitely.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Reintroduces TCPROS subscriber-side reconnect attempts so a subscriber can recover when its TCP connection dies (without waiting indefinitely for a publisherUpdate), improving resilience of rospy topic connections.

Changes:

  • Replaces the previous unbounded reconnect loop with a bounded, exponential-backoff _reconnect(max_attempts=4) helper.
  • Updates receive_loop() to attempt reconnection on TransportTerminated before exiting the loop.
  • Clears the read buffer after a successful reconnect to avoid feeding stale bytes to the deserializer.

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

Comment on lines 792 to 795
try:
# set a timeout so that we can continue polling for
# exit. 30. is a bit high, but I'm concerned about
# embedded platforms. To do this properly, we'd have
# to move to non-blocking routines.
self.connect(self.dest_address[0], self.dest_address[1], self.endpoint_id, timeout=30.)
except TransportInitError:
self.socket = None
Comment on lines +778 to +780
for attempt in range(max_attempts):
if self.done or rospy.is_shutdown():
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants