question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Re-connection Strategy

See original GitHub issue

Awesome Library.

I was taking a look at the re-connection handler and noticed it just takes a static delay before attempting to reconnect.

I usually like to use some form of re-connection strategy to control how a re-connection occurs for example an Exponential Back-off.

Would this be a suitable feature addition?

To keep the module size down the constructor could take a function:

new Sockette(..., {
  reconnection: (attempts, maxAttempts) => Number
});

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
ghostcommented, Feb 3, 2018

If your server can’t handle a couple of reconnects then you have serious problems server side. First off, even if you spam a server with tons and tons of SYN packets, the Linux kernel will just discard any such packet it cannot handle, fully according to TCP spec. The user space process will not even see those connection attempts, and the sender will just resend them in exponential backoff ways until the server can handle them. You don’t need to reinvent the wheel by implementing that same logic once again on top because it doesn’t make any difference. Latency + sender backoff is already achieving this for you. Also, any well-written server can handle millions of connections with no problem at all. Don’t let Socket.IO marketing buzz become what you call “source of truth” because those kind of projects rely on nothing but fancy words and marketing bullshit to make you think they actually achieve anything.

6reactions
ThisIsMissEmcommented, Feb 2, 2018

Hi! From someone who’s once built large scale websockets as a service infrastructure (many year ago), you’ll definitely want to introduce some jitter on reconnection, otherwise you’ll get a thundering herd problem, as described by other commenters.

Even if this is for 100-700ms, it’ll still give you time to process the connection attempt, and then try to handle it. The alternative is that you end up overload various aspects of your infrastructure, making it impossible to restart any single component. Additionally, a simple Math.random() * 500 can really make a difference. Sure, it might still be 1000-3000 clients reconnecting at once, but that’s far more manageable than 10,000 trying at once, even if those 3000 don’t all manage to successfully reconnect, it still cuts load on the subsequent reconnect attempt.

It’s great to make a small module, but with caching and service workers, that becomes practically irrelevant if an intermittent issue will make it really hard to recover availability due to a thundering herd. People will generally be reloading your page less than they will be reconnecting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reconnection Strategies | MuleSoft Documentation
You can configure a reconnection strategy for an operation either by modifying the operation properties or by modifying the configuration of the global ......
Read more >
reconnection-strategy in mule - liveBook · Manning
In chapter 9 we'll examine how to use a reconnection strategy in concert with the JMS transport. This will allow your Mule instances...
Read more >
Specifying a reconnection strategy - Diffusion Documentation
The reconnection behavior of a client session can be configured using reconnection strategies. A reconnection strategy is applied when the session enters the ......
Read more >
4. Connection Management - Getting Started with Mule Cloud ...
The standard reconnection strategy, reconnect , is a reconnection strategy that allows the user to configure how many times a reconnection should be...
Read more >
docs-mule-runtime/reconnection-strategy-about.adoc at v4.4
Configure an Operation Reconnection Strategy · None. Is the default behavior, which immediately returns a connectivity error if the attempt to connect is ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found