fanout/reconnecting-eventsource

Allow for random delay before reconnecting.

Closed this issue · 1 comments

First up, thanks for creating this library. It performs exactly as described and made our application's real-timey-ness significantly more stable.

We continuously deploy our NodeJS application and when the stream services that are connected to via EventSource are bounced, all open connections are closed. This library performs exactly as expected and all client instantly re-connect. The issue is that the simultaneous connection of all active clients floods the server with requests at the exact same time and this "first" stream connection is special in that it creates the live connection to the database.

I'd like to contribute a PR that allows for retry_time to optionally include some randomness. Before submitting a PR, I wanted to check if there was an implementation preference. I appreciate the constructor mimics the constructor for EventSource so my plan was to add a configuration option for retry time that includes some string constants, e.g RANDOM which reconnects between in 0-3 seconds after closing.

Random delay when reconnecting would be good. I'd say it doesn't need to be optional either, but should always happen, and maybe the user can select the maximum end of the range.

Feel free to send a PR!