Fix reconnection bug on Twisted#154
Merged
Merged
Conversation
`AutobahnRosBridgeClientFactory.connect()` registered the connector by calling `connectWS()` directly from the caller's thread, which does not wake the Twisted reactor. On the first connection this is harmless because the reactor is started (and processes the pending connector) right after. But on a later reconnect with the reactor already running, an idle reactor sits blocked in `select()` with no file descriptors and never notices the connector added from another thread, so the connection never completes and `run()` times out. This surfaced when reconnecting after a disconnect: for roughly `closeHandshakeTimeout` (5s) the closing connection keeps the reactor cycling, so a quick reconnect works, but waiting longer leaves the reactor idle and the reconnect hangs until timeout (e.g. toggling a Grasshopper ROS client off, waiting, and back on). Schedule the connection through `reactor.callFromThread()` (as `send_message`/`send_close` already do), which wakes the reactor. It is also safe before the reactor has started, since the call is queued and runs once it does. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
After a disconnect, if you reconnect within 5 seconds, everything works, but after that, the service gives up. Here's a fix for it.
This should address the bugs on #97 (comment), #98 and #121
What type of change is this?
Checklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.CHANGELOG.rstfile in theUnreleasedsection under the most fitting heading (e.g.Added,Changed,Removed).invoke test).invoke check).