microsoft / node-pty

Fork pseudoterminals in Node.JS
Other
1.42k stars 233 forks source link

[bug] posix_spawnp failed after calling spawn multiple times #670

Open fadezak100 opened 4 months ago

fadezak100 commented 4 months ago

Environment details

Issue description

I randomly get this error when calling spawn function multiple consecutive times:

/node_modules/node-pty/src/unixTerminal.ts:114
    const term = pty.fork(file, args, parsedEnv, cwd, this._cols, this._rows, uid, gid, (encoding === 'utf8'), helperPath, onexit);
                     ^
Error: posix_spawnp failed.

Here's a script to reproduce the problem.

import { spawn } from "node-pty"

const reproduce = async () => {
    for(let i = 0; i <= 1000; i++) {
        console.log(`the error is in ${i} iteration`)
        await spawn(`echo hello ${i}`, [], {
            name: 'xterm-color',
            cols: 80,
            rows: 30,
            cwd: process.env.HOME,
            env: process.env as any,
        })
    }
}

try {
    reproduce()
} catch (error) {
    console.error(error)
}