Skip to content

[Web runtime] Add reconnect-on-close and HTTP retry to the Browser SDK - #1569

Open
minggangw wants to merge 2 commits into
RobotWebTools:developfrom
minggangw:feat/web-sdk-reconnect
Open

[Web runtime] Add reconnect-on-close and HTTP retry to the Browser SDK#1569
minggangw wants to merge 2 commits into
RobotWebTools:developfrom
minggangw:feat/web-sdk-reconnect

Conversation

@minggangw

@minggangw minggangw commented Aug 7, 2026

Copy link
Copy Markdown
Member

This PR enhances the rclnodejs/web Browser SDK’s resilience by adding WebSocket reconnect-on-close with backoff and HTTP retry-with-backoff behavior, plus corresponding public typings and tests.

Changes:

  • Implement WebSocket reconnect-on-close with exponential backoff + jitter, subscription replay, and lifecycle events (disconnected/reconnecting/reconnected).
  • Add HTTP retry-with-backoff for call()/publish() on network errors and 5xx responses via httpRetries.
  • Add a new test suite covering WS reconnect behavior and HTTP retries.

Fix: #1510

Copilot AI lite review requested due to automatic review settings August 7, 2026 10:03

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

This PR enhances the rclnodejs/web Browser SDK’s resilience by adding WebSocket reconnect-on-close with backoff and HTTP retry-with-backoff behavior, plus corresponding public typings and tests.

Changes:

  • Implement WebSocket reconnect-on-close with exponential backoff + jitter, subscription replay, and lifecycle events (disconnected/reconnecting/reconnected).
  • Add HTTP retry-with-backoff for call()/publish() on network errors and 5xx responses via httpRetries.
  • Add a new test suite covering WS reconnect behavior and HTTP retries.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
web/index.d.ts Updates public types/docs to expose reconnect, httpRetries, and lifecycle event on/off APIs.
web/client.js Implements reconnect/backoff logic (WS + HTTP), lifecycle event listeners, and wires new options into transports.
test/test-web-reconnect.js Adds coverage for WS reconnect semantics and HTTP retry behavior.

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

Comment thread web/client.js
Comment on lines 131 to 135
const onError = (err) => {
if (this._pending.size === 0 && !this._closed) {
// Ignore post-open: 'close' always follows and _handleClose() owns failing pending requests.
if (!settled) {
settled = true;
reject(err && err.error ? err.error : err);
Comment thread web/client.js
Comment on lines +163 to +178
_handleClose() {
this._failAll(_connectionLostError());
if (this._userClosed) {
this._closed = true;
this._subs.clear();
return;
}
this._onEvent('disconnected', undefined);
if (!this._reconnect) {
this._closed = true;
this._subs.clear();
return;
}
this._reconnecting = true;
this._scheduleReconnect();
}
Comment thread web/client.js
Comment on lines +517 to +520
/**
* Subscribe to an SDK lifecycle event: 'disconnected', 'reconnecting'
* ({attempt, delay}), or 'reconnected'. Only fires with {reconnect: true}.
*/
Comment thread web/client.js Outdated
Comment on lines +244 to +247
if (!this._ws || this._closed) return;
const ws = this._ws;
// Already closed (e.g. mid-backoff) means 'close' won't fire again.
if (ws.readyState === 3) return;
@coveralls

coveralls commented Aug 7, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 91.093% (-0.009%) from 91.102% — minggangw:feat/web-sdk-reconnect into RobotWebTools:develop

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.

Browser ↔ ROS 2 capability runtime (Web Runtime)

3 participants