ssh-client-wrapper 3.4.2 → 3.4.3

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.
Files changed (2) hide show
  1. package/lib/util.js +15 -6
  2. package/package.json +1 -1
package/lib/util.js CHANGED
@@ -402,13 +402,18 @@ export const sendPty = async (pty, message, logger, label)=>{
402
402
  };
403
403
 
404
404
  /**
405
- * close the input pipe of a pty which has exited, so that its conhost.exe can go away (win32 only).
405
+ * release what node-pty (ConPTY) leaves behind when a pty has exited (win32 only).
406
406
  *
407
- * node-pty (ConPTY) never closes the write end of the console input pipe, neither when the child exits nor in kill().
408
- * The headless conhost.exe of the pty stays alive as long as that pipe is open, so every pty leaks one conhost.exe
409
- * until the node process ends. After about 1600 of them the system runs out of resources
410
- * (rsync.exe fails with 0xC000012D / 0xC0000142, node dies with "Out of memory").
411
- * This touches a private field of node-pty; it does nothing if the field is not there.
407
+ * node-pty never frees these two resources of a pty, neither when the child exits nor in kill():
408
+ * - the write end of the console input pipe. The headless conhost.exe of the pty stays alive as long as it is open,
409
+ * so every pty leaks one conhost.exe until the node process ends.
410
+ * - the worker thread which drains the console output pipe (ConoutConnection). It is stopped by dispose(),
411
+ * which only kill() calls. Every pty leaks a thread and its V8 isolate (about 10 MB).
412
+ * After about 1600 ptys the system runs out of resources
413
+ * (rsync.exe fails with 0xC000012D / 0xC0000142, node dies with "Out of memory" or "Cannot launch conpty").
414
+ * kill() is not used because it forks a node process per call and may send process.kill() to a recycled PID.
415
+ * dispose() waits one second for the remaining output before it stops the worker.
416
+ * This touches private fields of node-pty; it does nothing for fields which are not there.
412
417
  * @param {object} pty - pty object returned by node-pty spawn()
413
418
  * @param {string} [platform] - platform name (injectable for tests)
414
419
  */
@@ -420,6 +425,10 @@ export const releasePty = (pty, platform = process.platform)=>{
420
425
  if (inSocket && !inSocket.destroyed && typeof inSocket.destroy === "function") {
421
426
  inSocket.destroy();
422
427
  }
428
+ const conout = pty?._agent?._conoutSocketWorker;
429
+ if (conout && typeof conout.dispose === "function") {
430
+ conout.dispose();
431
+ }
423
432
  };
424
433
 
425
434
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh-client-wrapper",
3
- "version": "3.4.2",
3
+ "version": "3.4.3",
4
4
  "description": "wrapper library for open ssh client and rsync",
5
5
  "keywords": [
6
6
  "ssh",