MQTT.js icon indicating copy to clipboard operation
MQTT.js copied to clipboard

Change reconnect logic to exponential backoff with random delay

Open sclausen opened this issue 7 years ago • 7 comments

If a client loses the connection, the reconnect starts immediately. If your broker died and you restart it, all clients try to connect at the same time and may cause problems with traffic, or authorization logic and maybe kill it again. So in my opinion the reconnect should be changed to an exponential backoff with jitter, explained in this article.

What do you think about this idea?

sclausen avatar Mar 09 '17 08:03 sclausen

Would you mind to send a PR? I think we should also cap the max timeout.

mcollina avatar Mar 09 '17 09:03 mcollina

Okay, I'll dig into the code and prepare something.

sclausen avatar Mar 09 '17 14:03 sclausen

Has been finished? It's a good job @sclausen

leesenlen avatar Aug 29 '17 02:08 leesenlen

Yes, that's what I've got so far. Any thoughts about the code?

sclausen avatar Aug 30 '17 07:08 sclausen

I thought mcollina is right; You shoud define a strategy with object; With this object, you can define retry_strategy with params such as delay_time, max_attempts, delay_random_range etc...

It's would be a strategy which support random delay or the other custom-supported-strategy;

And also you can define actions of the object(like mcollina said); It would be helpful to control the reconnection process;

Err.. btw, it would be a lot of works

leesenlen avatar Aug 30 '17 10:08 leesenlen

Has this issue been resolved yet?

shivamydv avatar Oct 18 '21 04:10 shivamydv

@shivamydv No, this issue is still marked as open.

sclausen avatar Oct 18 '21 14:10 sclausen

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.

github-actions[bot] avatar Oct 19 '22 02:10 github-actions[bot]

This issue was automatically closed due to inactivity.

github-actions[bot] avatar Nov 03 '22 02:11 github-actions[bot]