starknet 10.5.0 → 10.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -7385,9 +7385,15 @@ var WebSocketChannel = class {
7385
7385
  reconnectAttempts = 0;
7386
7386
  userInitiatedClose = false;
7387
7387
  reconnectTimeoutId = null;
7388
+ // Fires once a (re)connection has stayed open long enough to be considered stable,
7389
+ // resetting the reconnection attempt counter.
7390
+ reconnectStabilityTimeoutId = null;
7388
7391
  requestQueue = [];
7389
7392
  events = new EventEmitter();
7390
- openListener = (ev) => this.events.emit("open", ev);
7393
+ openListener = (ev) => {
7394
+ this.scheduleReconnectAttemptsReset();
7395
+ this.events.emit("open", ev);
7396
+ };
7391
7397
  closeListener = this.onCloseProxy.bind(this);
7392
7398
  messageListener = this.onMessageProxy.bind(this);
7393
7399
  errorListener = (ev) => this.events.emit("error", ev);
@@ -7407,7 +7413,8 @@ var WebSocketChannel = class {
7407
7413
  this.reconnectOptions = {
7408
7414
  retries: options.reconnectOptions?.retries ?? 5,
7409
7415
  delay: options.reconnectOptions?.delay ?? 2e3,
7410
- exponential: options.reconnectOptions?.exponential ?? true
7416
+ exponential: options.reconnectOptions?.exponential ?? true,
7417
+ stableConnectionThreshold: options.reconnectOptions?.stableConnectionThreshold ?? 5e3
7411
7418
  };
7412
7419
  this.requestTimeout = options.requestTimeout ?? 6e4;
7413
7420
  this.WsImplementation = options.websocket || config.get("websocket") || ws_default;
@@ -7554,8 +7561,12 @@ var WebSocketChannel = class {
7554
7561
  clearTimeout(this.reconnectTimeoutId);
7555
7562
  this.reconnectTimeoutId = null;
7556
7563
  }
7557
- this.websocket.close(code, reason);
7564
+ if (this.reconnectStabilityTimeoutId) {
7565
+ clearTimeout(this.reconnectStabilityTimeoutId);
7566
+ this.reconnectStabilityTimeoutId = null;
7567
+ }
7558
7568
  this.userInitiatedClose = true;
7569
+ this.websocket.close(code, reason);
7559
7570
  }
7560
7571
  /**
7561
7572
  * Returns a Promise that resolves when the WebSocket connection is closed.
@@ -7642,12 +7653,30 @@ var WebSocketChannel = class {
7642
7653
  });
7643
7654
  await Promise.all(restorePromises);
7644
7655
  }
7656
+ /**
7657
+ * Reset the reconnection attempt counter, but only once the current connection has
7658
+ * stayed open for `stableConnectionThreshold` ms. A connection that opens and then
7659
+ * immediately drops (a flapping gateway) never reaches this point, so its attempts
7660
+ * keep accumulating toward the retry cap instead of resetting every cycle.
7661
+ */
7662
+ scheduleReconnectAttemptsReset() {
7663
+ if (this.reconnectStabilityTimeoutId) {
7664
+ clearTimeout(this.reconnectStabilityTimeoutId);
7665
+ }
7666
+ this.reconnectStabilityTimeoutId = setTimeout(() => {
7667
+ this.reconnectAttempts = 0;
7668
+ this.reconnectStabilityTimeoutId = null;
7669
+ }, this.reconnectOptions.stableConnectionThreshold);
7670
+ }
7645
7671
  _startReconnect() {
7646
7672
  if (this.isReconnecting || !this.autoReconnect) {
7647
7673
  return;
7648
7674
  }
7675
+ if (this.reconnectStabilityTimeoutId) {
7676
+ clearTimeout(this.reconnectStabilityTimeoutId);
7677
+ this.reconnectStabilityTimeoutId = null;
7678
+ }
7649
7679
  this.isReconnecting = true;
7650
- this.reconnectAttempts = 0;
7651
7680
  const tryReconnect = () => {
7652
7681
  if (this.reconnectAttempts >= this.reconnectOptions.retries) {
7653
7682
  logger.error("WebSocket: Maximum reconnection retries reached. Giving up.");
@@ -7662,7 +7691,6 @@ var WebSocketChannel = class {
7662
7691
  this.websocket.onopen = async () => {
7663
7692
  logger.info("WebSocket: Reconnection successful.");
7664
7693
  this.isReconnecting = false;
7665
- this.reconnectAttempts = 0;
7666
7694
  await this._restoreSubscriptions();
7667
7695
  this._processRequestQueue();
7668
7696
  this.events.emit("open", new Event("open"));