reconnecting-websocket
reconnecting-websocket copied to clipboard
Bug: `_getNextDelay` returns `0` while a socket may be reconnecting/connecting
@bytemain there is a bug in the code causing socket to attempt to reconnect in 0ms
which causes uncaught exception (e.g. if you're using ws
package).
function _getNextDelay() {
const {
reconnectionDelayGrowFactor = DEFAULT.reconnectionDelayGrowFactor,
minReconnectionDelay = DEFAULT.minReconnectionDelay,
maxReconnectionDelay = DEFAULT.maxReconnectionDelay
} = this._options;
let delay = 0;
if (this._retryCount > 0) {
delay =
minReconnectionDelay *
reconnectionDelayGrowFactor ** (this._retryCount - 1);
if (delay > maxReconnectionDelay) {
delay = maxReconnectionDelay;
}
- }
+ } else {
+ // -1 `_retryCount` indicates it's reconnecting so wait at least 1s
+ delay = 1000;
+ }
this._debug('next delay', delay);
return delay;
}