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.js CHANGED
@@ -7568,9 +7568,15 @@ var WebSocketChannel = class {
7568
7568
  reconnectAttempts = 0;
7569
7569
  userInitiatedClose = false;
7570
7570
  reconnectTimeoutId = null;
7571
+ // Fires once a (re)connection has stayed open long enough to be considered stable,
7572
+ // resetting the reconnection attempt counter.
7573
+ reconnectStabilityTimeoutId = null;
7571
7574
  requestQueue = [];
7572
7575
  events = new EventEmitter();
7573
- openListener = (ev) => this.events.emit("open", ev);
7576
+ openListener = (ev) => {
7577
+ this.scheduleReconnectAttemptsReset();
7578
+ this.events.emit("open", ev);
7579
+ };
7574
7580
  closeListener = this.onCloseProxy.bind(this);
7575
7581
  messageListener = this.onMessageProxy.bind(this);
7576
7582
  errorListener = (ev) => this.events.emit("error", ev);
@@ -7590,7 +7596,8 @@ var WebSocketChannel = class {
7590
7596
  this.reconnectOptions = {
7591
7597
  retries: options.reconnectOptions?.retries ?? 5,
7592
7598
  delay: options.reconnectOptions?.delay ?? 2e3,
7593
- exponential: options.reconnectOptions?.exponential ?? true
7599
+ exponential: options.reconnectOptions?.exponential ?? true,
7600
+ stableConnectionThreshold: options.reconnectOptions?.stableConnectionThreshold ?? 5e3
7594
7601
  };
7595
7602
  this.requestTimeout = options.requestTimeout ?? 6e4;
7596
7603
  this.WsImplementation = options.websocket || config.get("websocket") || ws_default;
@@ -7737,8 +7744,12 @@ var WebSocketChannel = class {
7737
7744
  clearTimeout(this.reconnectTimeoutId);
7738
7745
  this.reconnectTimeoutId = null;
7739
7746
  }
7740
- this.websocket.close(code, reason);
7747
+ if (this.reconnectStabilityTimeoutId) {
7748
+ clearTimeout(this.reconnectStabilityTimeoutId);
7749
+ this.reconnectStabilityTimeoutId = null;
7750
+ }
7741
7751
  this.userInitiatedClose = true;
7752
+ this.websocket.close(code, reason);
7742
7753
  }
7743
7754
  /**
7744
7755
  * Returns a Promise that resolves when the WebSocket connection is closed.
@@ -7825,12 +7836,30 @@ var WebSocketChannel = class {
7825
7836
  });
7826
7837
  await Promise.all(restorePromises);
7827
7838
  }
7839
+ /**
7840
+ * Reset the reconnection attempt counter, but only once the current connection has
7841
+ * stayed open for `stableConnectionThreshold` ms. A connection that opens and then
7842
+ * immediately drops (a flapping gateway) never reaches this point, so its attempts
7843
+ * keep accumulating toward the retry cap instead of resetting every cycle.
7844
+ */
7845
+ scheduleReconnectAttemptsReset() {
7846
+ if (this.reconnectStabilityTimeoutId) {
7847
+ clearTimeout(this.reconnectStabilityTimeoutId);
7848
+ }
7849
+ this.reconnectStabilityTimeoutId = setTimeout(() => {
7850
+ this.reconnectAttempts = 0;
7851
+ this.reconnectStabilityTimeoutId = null;
7852
+ }, this.reconnectOptions.stableConnectionThreshold);
7853
+ }
7828
7854
  _startReconnect() {
7829
7855
  if (this.isReconnecting || !this.autoReconnect) {
7830
7856
  return;
7831
7857
  }
7858
+ if (this.reconnectStabilityTimeoutId) {
7859
+ clearTimeout(this.reconnectStabilityTimeoutId);
7860
+ this.reconnectStabilityTimeoutId = null;
7861
+ }
7832
7862
  this.isReconnecting = true;
7833
- this.reconnectAttempts = 0;
7834
7863
  const tryReconnect = () => {
7835
7864
  if (this.reconnectAttempts >= this.reconnectOptions.retries) {
7836
7865
  logger.error("WebSocket: Maximum reconnection retries reached. Giving up.");
@@ -7845,7 +7874,6 @@ var WebSocketChannel = class {
7845
7874
  this.websocket.onopen = async () => {
7846
7875
  logger.info("WebSocket: Reconnection successful.");
7847
7876
  this.isReconnecting = false;
7848
- this.reconnectAttempts = 0;
7849
7877
  await this._restoreSubscriptions();
7850
7878
  this._processRequestQueue();
7851
7879
  this.events.emit("open", new Event("open"));