Skip to content

frontend: Fix MAVLink2Rest orphan WebSocket reconnects - #4030

Closed
joaoantoniocardoso wants to merge 1 commit into
masterfrom
pr/mavlink2rest-orphan-reconnect
Closed

frontend: Fix MAVLink2Rest orphan WebSocket reconnects#4030
joaoantoniocardoso wants to merge 1 commit into
masterfrom
pr/mavlink2rest-orphan-reconnect

Conversation

@joaoantoniocardoso

@joaoantoniocardoso joaoantoniocardoso commented Jul 25, 2026

Copy link
Copy Markdown
Member

Summary

  • On intentional close, clear reconnect timeouts and detach onclose so dying sockets cannot resurrect.
  • setBaseUrl closes the previous send socket before opening a new one (probe can call setBaseUrl more than once).

Test plan

  • Load BlueOS, confirm MAVLink heartbeats / params still work
  • Reload / HMR: console should not accumulate reconnecting zombie WS over time
  • Vehicle reconnect after autopilot restart still recovers within a few seconds

Disable reconnect on intentional close and close the previous send
socket in setBaseUrl so probe/url changes cannot leave zombie sockets.
@joaoantoniocardoso
joaoantoniocardoso marked this pull request as draft July 25, 2026 15:51
@joaoantoniocardoso
joaoantoniocardoso marked this pull request as ready for review July 25, 2026 15:51
@bluerobotics bluerobotics deleted a comment from github-actions Bot Jul 25, 2026
@joaoantoniocardoso
joaoantoniocardoso marked this pull request as draft July 25, 2026 16:14
@joaoantoniocardoso
joaoantoniocardoso marked this pull request as ready for review July 25, 2026 16:14
@github-actions

Copy link
Copy Markdown

Automated PR Review

0. Summary

  • Verdict: MINOR SUGGESTIONS ✏️

Adds an intentionalClose flag and tracked reconnectTimeout to both Endpoint and Mavlink2RestManager, plus a helper that detaches onclose/onmessage/onerror and clears pending reconnects before replacing the socket. This fixes the "zombie" behavior where an old socket's onclose could keep resurrecting itself in parallel with the new one. Logic looks correct: updateUrl/setBaseUrl set the flag → null the handler → cancel the timer → close → build a fresh socket that resets the flag.

6. Code Quality & Style

  • 6.1 [nit] core/frontend/src/libs/MAVLink2Rest/Endpoint.ts:14/core/frontend/src/libs/MAVLink2Rest/index.ts:91 — the two socket owners diverged on how they carry the URL. Endpoint now stores this.url and reconnects via this.createSocket(this.url); Mavlink2RestManager.createSocket still closes over the url parameter (this.createSocket(url)). Both are safe because closeIntentionally()/closeSendSocket() clear the pending timeout before a new URL is used, but the asymmetry is easy to trip on later — consider mirroring the Endpoint pattern (store this.sendUrl) so the two files read identically.
  • 6.2 [nit] core/frontend/src/libs/MAVLink2Rest/Endpoint.ts:40 and core/frontend/src/libs/MAVLink2Rest/index.ts:110intentionalClose is reset to false at the top of createSocket(). It works today only because callers always call the "close" helper immediately before createSocket(), so no other code path can observe the flag in the wrong state. Setting the flag in the caller (updateUrl/setBaseUrl) instead of resetting it inside createSocket would make the invariant local and self-documenting.

7. Tests

  • 7.1 [minor] No automated coverage is added for the reconnect state machine. The test plan is manual (heartbeats work, no zombie WS accumulation across reloads, autopilot restart recovers). A small unit test around Endpoint with a mocked WebSocket (verifying that a synthesized onclose after updateUrl() does not schedule a reconnect) would guard against regressions here — this is exactly the kind of bug that is invisible until logs pile up.

8. Documentation

  • 8.1 [minor] core/frontend/src/libs/MAVLink2Rest/index.ts bundles unrelated cleanups with the fix: import reordering (autopilot_data, MavCmd, MAVLinkType), trailing-comma additions in sendCommandLong, timeout_seconds: number = 3timeout_seconds = 3 in waitForAck, timeout_seconds*1000timeout_seconds * 1000, removal of a blank line, and a trailing-space trim in a JSDoc comment. These are all valid simple-import-sort / airbnb style fixes, but mixing them into the reconnect-fix commit muddies git blame/git bisect. Prefer isolating the behavioral fix in its own commit and running the auto-fixer in a separate one.

Generated by PR Review Bot. This is advisory, a human reviewer must still approve.

@joaoantoniocardoso

Copy link
Copy Markdown
Member Author

Acknowledging the latest review nits (URL storage asymmetry / style / tests / commit split). Leaving as follow-ups — behavior fix is complete as-is.

@joaoantoniocardoso joaoantoniocardoso added the move-to-stable Needs to be cherry-picked and move to stable label Jul 25, 2026
@joaoantoniocardoso

Copy link
Copy Markdown
Member Author

Superseded by #4044 (same changes, head moved to fork joaoantoniocardoso/BlueOS-docker).

@joaoantoniocardoso

Copy link
Copy Markdown
Member Author

Closed in favor of #4044.

@joaoantoniocardoso
joaoantoniocardoso deleted the pr/mavlink2rest-orphan-reconnect branch July 27, 2026 21:03
@joaoantoniocardoso joaoantoniocardoso removed the move-to-stable Needs to be cherry-picked and move to stable label Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant