fetch-event-source icon indicating copy to clipboard operation
fetch-event-source copied to clipboard

Exponential reconnect backoff

Open chris-aeviator opened this issue 2 years ago • 2 comments
trafficstars

When fetch-event-source loses it's connection to the server, it tries to reconnect rather aggressively. Given enough clients, this continious repeating traffic pattern may pose an unneccesary risk of overloading a router/ load balancer that might still be receiving the traffic.

grafik

This issue proposes to implement an exponential backoff behavior that increases the reconnect time with each unsuccessful reconnect iteration (see https://www.npmjs.com/package/exponential-backoff for an example implementation)

chris-aeviator avatar Aug 31 '23 19:08 chris-aeviator

I also have the same issue but I fixed it by throwing an error from inside the onerror function.

onerror() {
    // do something
    throw new Error(); // hack to close the connection
}

As suggested by @jchiare in https://github.com/Azure/fetch-event-source/issues/24#issuecomment-1465768867

BilalTariq01 avatar Sep 04 '23 12:09 BilalTariq01

Thanks for sharing this. I wouldn’t want to close the connection but it’s a great place to introduce an artificial delay.

Am 04.09.2023 um 14:10 schrieb Bilal Tariq @.***>:

 I also have the same issue but I fixed it by throwing an error from inside the onerror function.

onerror() { // do something throw new Error(); // hack to close the connection } — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

chris-aeviator avatar Sep 04 '23 16:09 chris-aeviator