Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/Question]: Dynamic reconnectPeriod (read Backoff strategy) #1742

Open
olso-nordsec opened this issue Nov 17, 2023 · 2 comments
Open
Labels

Comments

@olso-nordsec
Copy link
Contributor

olso-nordsec commented Nov 17, 2023

Hi,

I wanted to get your opinion on this. It seems there is no official approach to have dynamic reconnectPeriod.

But it is possible to reuse the same concept as laid out in https://github.com/mqttjs/MQTT.js#refresh-authentication-options--signed-urls-with-transformwsurl-websocket-only via transformWsUrl

const transformWsUrl = (url, options, client) => {
  // dynamic reconnectPeriod example
  client.options.reconnectPeriod = this.backoff.current().delay;

  client.options.username = `token=${this.get_current_auth_token()}`;
  client.options.clientId = `${this.get_updated_clientId()}`;

  return `${this.get_signed_cloud_url(url)}`;
}

const connection = await mqtt.connectAsync(<wss url>, {
  ...,
  transformWsUrl: transformUrl,
});

// somewhere in code on events `connect|reconnect|close|disconnect|offline|error|end`
this.backoff.increase();
this.backoff.decrease();

On which of these lifecycle events should/would you increase+decrease reconnectPeriod?

When I've tried playing with events, it seems sometimes I'm getting multiple events firings of same type.

This makes it difficult to distinguish which event is actionable for increase/decrease.

@robertsLando
Copy link
Member

I like the idea, anyway I think this should be fixed before: #419

Copy link

This is an automated message to let you know that this issue has
gone 365 days without any activity. In order to ensure that we work
on issues that still matter, this issue will be closed in 14 days.

If this issue is still important, you can simply comment with a
"bump" to keep it open.

Thank you for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants