@ai-ecoverse/slicc-kernel 1.26.0 → 1.26.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/node.js CHANGED
@@ -2454,6 +2454,7 @@ Sec-WebSocket-Accept: ${accept2}\r
2454
2454
  // src/cdp/facade.ts
2455
2455
  var MAX_HEAD = 64 * 1024;
2456
2456
  var LIST_TIMEOUT = 1e4;
2457
+ var CLOSE_WAIT_MS = 1e3;
2457
2458
  function respond(status, body, type = "text/plain; charset=utf-8") {
2458
2459
  const bytes = new TextEncoder().encode(body);
2459
2460
  const head = latin1Bytes(
@@ -2599,7 +2600,11 @@ var CdpFacade = class {
2599
2600
  async upgrade(conn, incoming, req, runtime) {
2600
2601
  const accept2 = await acceptKey(req.headers);
2601
2602
  const host = await this.host(runtime);
2602
- await new Relay(conn, incoming, host, this.options.maxMessage ?? MAX_MESSAGE, this.stop.signal).start(switchingHead(accept2)).finally(() => host.close());
2603
+ const limits = {
2604
+ max: this.options.maxMessage ?? MAX_MESSAGE,
2605
+ closeWaitMs: this.options.closeWaitMs ?? CLOSE_WAIT_MS
2606
+ };
2607
+ await new Relay(conn, incoming, host, limits, this.stop.signal).start(switchingHead(accept2)).finally(() => host.close());
2603
2608
  }
2604
2609
  };
2605
2610
  var Relay = class {
@@ -2609,12 +2614,14 @@ var Relay = class {
2609
2614
  incoming;
2610
2615
  host;
2611
2616
  max;
2617
+ closeWaitMs;
2612
2618
  stop;
2613
- constructor(conn, incoming, host, max, stop) {
2619
+ constructor(conn, incoming, host, limits, stop) {
2614
2620
  this.conn = conn;
2615
2621
  this.incoming = incoming;
2616
2622
  this.host = host;
2617
- this.max = max;
2623
+ this.max = limits.max;
2624
+ this.closeWaitMs = limits.closeWaitMs;
2618
2625
  this.stop = stop;
2619
2626
  }
2620
2627
  send(bytes) {
@@ -2640,8 +2647,15 @@ var Relay = class {
2640
2647
  void this.end(CLOSE.tooBig, `a message is over ${this.max} bytes`);
2641
2648
  else void this.send(frame(OP_TEXT, bytes));
2642
2649
  };
2643
- await Promise.race([this.pump(), hostGone]);
2650
+ const pumping = this.pump();
2651
+ await Promise.race([pumping, hostGone]);
2644
2652
  await this.writes;
2653
+ let timer;
2654
+ const waited = new Promise((resolve) => {
2655
+ timer = setTimeout(resolve, this.closeWaitMs);
2656
+ });
2657
+ await Promise.race([pumping, waited]);
2658
+ clearTimeout(timer);
2645
2659
  }
2646
2660
  async pump() {
2647
2661
  const reader = new WsReader(this.incoming, this.max);