@intuned/runtime-dev 1.3.24-pipe.7 → 1.3.24-pipe.8

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.
@@ -418,7 +418,7 @@ var require_interfaceClient = __commonJS({
418
418
  yield JSON.parse(data.toString());
419
419
  }
420
420
  }
421
- async close() {
421
+ async close(mode = "client") {
422
422
  console.log(`[${process.pid}] Closing socket client`);
423
423
  if (this.dataListener) {
424
424
  this.socket.off("data", this.dataListener);
@@ -428,9 +428,33 @@ var require_interfaceClient = __commonJS({
428
428
  }
429
429
  this.closeAbortController.abort();
430
430
  console.log(`[${process.pid}] Called abort on closeAbortController`);
431
- console.log(`[${process.pid}] Sending FIN to socket`);
432
- await (0, util_1.promisify)((cb) => this.socket.end(cb))();
433
- console.log(`[${process.pid}] Socket finished, destroying`);
431
+ if (mode === "client") {
432
+ console.log(`[${process.pid}] Sending FIN to socket`);
433
+ await (0, util_1.promisify)((cb) => this.socket.end(cb))();
434
+ const closeResult = await Promise.race([
435
+ new Promise((resolve) => this.socket.once("close", () => resolve("closed"))),
436
+ new Promise((resolve) => this.socket.once("error", () => resolve("error"))),
437
+ (0, promises_1.setTimeout)(3e3, "timeout")
438
+ ]);
439
+ console.log(`[${process.pid}] Socket close result: ${closeResult}`);
440
+ if (closeResult === "timeout") {
441
+ console.warn(`[${process.pid}] Socket did not close within timeout, destroying socket`);
442
+ this.socket.destroy();
443
+ }
444
+ return;
445
+ }
446
+ const receiveEndResult = await Promise.race([
447
+ new Promise((resolve) => this.socket.once("end", () => resolve("end"))),
448
+ new Promise((resolve) => this.socket.once("error", () => resolve("error"))),
449
+ (0, promises_1.setTimeout)(3e3, "timeout")
450
+ ]);
451
+ console.log(`[${process.pid}] Socket receive end result: ${receiveEndResult}`);
452
+ if (receiveEndResult === "end") {
453
+ console.log(`[${process.pid}] Socket ended gracefully`);
454
+ await (0, util_1.promisify)((cb) => this.socket.end(cb))();
455
+ return;
456
+ }
457
+ console.log(`[${process.pid}] Socket did not end gracefully, destroying socket`);
434
458
  this.socket.destroy();
435
459
  }
436
460
  get closed() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
- "version": "1.3.24-pipe.7",
3
+ "version": "1.3.24-pipe.8",
4
4
  "description": "Intuned runtime",
5
5
  "packageManager": "yarn@4.12.0",
6
6
  "main": "./dist/index.js",