Bring back re-connect logic#58
Open
jprestwo wants to merge 1 commit into
Open
Conversation
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.
There was a problem hiding this comment.
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 onTransportTerminatedbefore 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.