Skip to content

Instantly share code, notes, and snippets.

@firxworx
Created August 5, 2022 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firxworx/8555597d9ccc93c115b5cdf7c727b6ac to your computer and use it in GitHub Desktop.
Save firxworx/8555597d9ccc93c115b5cdf7c727b6ac to your computer and use it in GitHub Desktop.
nodejs child processes

from: prisma/prisma#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

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

console.log('hao', process.pid)
setTimeout(() => {
  console.log('hi')
}, 100000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment