node-pty icon indicating copy to clipboard operation
node-pty copied to clipboard

Possible pseudo-terminal descriptors leak

Open destitutus opened this issue 1 year ago • 0 comments
trafficstars

Environment details

  • OS: Distributor ID: Ubuntu

  • OS version: Description: Ubuntu 22.04.3 LTS Release: 22.04 Codename: jammy

  • node-pty version: 1.0.0

Issue description

After spawning two terminals and closing the first, the number of terminals used by the system does not decrease.

sudo /sbin/sysctl -a | grep kernel.pty

# or

ls -al /dev/pts | wc -l

Code to reproduce

import * as os from 'node:os'
import * as pty from 'node-pty'


function runTestShell() {
  const ptyProcess = pty.spawn('bash', [], {
    name: 'xterm-color',
    cols: 80,
    rows: 30
  })

  ptyProcess.onData((data) => {
    process.stdout.write(data)
  })
  ptyProcess.write('tty\n')
  return ptyProcess
}

const p1 = runTestShell()
const p2 = runTestShell()

setTimeout(() => {
  console.log('destroy!')
  p1.destroy()
}, 5000)

Ways to check.

  1. Check the count of resources with sudo /sbin/sysctl -a | grep kernel.pty.nr
  2. Run js script and check the count of resources before calling destroy on p1
  3. Check the count of resources after calling destroy on p1
  4. Check the count of resources after script termination

destitutus avatar Nov 30 '23 17:11 destitutus