Skip to content

Instantly share code, notes, and snippets.

@firxworx
Created August 5, 2022 03:22
Show Gist options
  • Select an option

  • Save firxworx/8555597d9ccc93c115b5cdf7c727b6ac to your computer and use it in GitHub Desktop.

Select an option

Save firxworx/8555597d9ccc93c115b5cdf7c727b6ac to your computer and use it in GitHub Desktop.

Revisions

  1. firxworx created this gist Aug 5, 2022.
    29 changes: 29 additions & 0 deletions node-spawn.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@

    from: <https://github.com/prisma/prisma/issues/2917>

    > The reason Prisma is cleaning up its child processes, is we'll end up with a dangling child process.
    So unfortunately Node.js does not make sure, that the child process is killed properly.
    That's why Prisma Client is cleaning this up, for now, to not introduce a foot gun for Prisma users.

    index.js

    ```ts
    const { spawn } = require('child_process')
    const path = require('path')
    const child = spawn('node', [path.join(__dirname, 'run.js')], {
    stdio: 'inherit',
    })
    setTimeout(() => {
    process.exit()
    }, 100)
    ```

    run.js

    ```ts
    console.log('hao', process.pid)
    setTimeout(() => {
    console.log('hi')
    }, 100000000)

    ```