Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: _getNextDelay returns 0 while a socket may be reconnecting/connecting #199

Open
titanism opened this issue Jul 3, 2024 · 0 comments

Comments

@titanism
Copy link

titanism commented Jul 3, 2024

@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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant