Skip to content

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

@titanism

Description

@titanism

@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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions