@mclawnet/agent 0.6.28 → 0.6.29

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.
@@ -1205,14 +1205,26 @@ var HubConnection = class {
1205
1205
  *
1206
1206
  * We `removeAllListeners()` before terminating so the close handler can't
1207
1207
  * also call `scheduleReconnect()` — single-entry reconnect is easier to
1208
- * reason about than relying on the timer-slot idempotency check.
1208
+ * reason about than relying on the timer-slot idempotency check. We then
1209
+ * re-attach a no-op `error` listener: terminating a socket still in
1210
+ * CONNECTING state (very common right after a wake — the post-sleep
1211
+ * reconnect attempt may not have completed the handshake yet) emits an
1212
+ * asynchronous `error` event, and an unhandled `error` on a WebSocket
1213
+ * (which extends EventEmitter) crashes the whole process.
1209
1214
  */
1210
1215
  terminateAndReconnect(reason) {
1211
1216
  this.stopHeartbeat();
1212
1217
  if (this.ws) {
1213
- this.ws.removeAllListeners();
1218
+ const ws = this.ws;
1219
+ ws.removeAllListeners();
1220
+ ws.on("error", () => {
1221
+ });
1214
1222
  try {
1215
- this.ws.terminate();
1223
+ if (ws.readyState === WebSocket.CONNECTING) {
1224
+ ws.close();
1225
+ } else {
1226
+ ws.terminate();
1227
+ }
1216
1228
  } catch {
1217
1229
  }
1218
1230
  this.ws = null;
@@ -3185,4 +3197,4 @@ export {
3185
3197
  FsBridge,
3186
3198
  startAgent
3187
3199
  };
3188
- //# sourceMappingURL=chunk-NQ3WFEXY.js.map
3200
+ //# sourceMappingURL=chunk-Y4J44CKF.js.map