Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a process uses process.exit(0), generation of the report will fail #463

Open
Stono opened this issue Dec 22, 2023 · 1 comment
Open
Assignees

Comments

@Stono
Copy link

Stono commented Dec 22, 2023

If you do this:

const interval = setInterval(() => {
  console.log('hi')
}, 1000)

const stop = () => {
  console.log('stopping')
  clearInterval(interval)
  process.exit(0)
}

process.on('SIGINT', stop)
process.on('SIGTERM', stop)

eg, capture SIGINT, SIGTERM and then process.exit once you've gracefully shut down, generation will fail with:

[    ] Received Ctrl+C, closing process...SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at /Users/Karl.Stoney/.nvm/versions/node/v18.16.1/lib/node_modules/clinic/node_modules/@clinic/heap-profiler/src/analysis/index.js:126:50
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)

Changing that to setTimeout(() => { process.exit(0), 2500 }) for example; "fixes" it, giving the report time to finish.

This is quite a common pattern in all the apps i work on, and in very common frameworks like nextjs; https://github.com/vercel/next.js/blob/b3ad907d2bbe5f16988565ca6e99d434084bded0/packages/next/src/server/lib/start-server.ts#L285

@alfonsograziano
Copy link

Hey! I would like to work on it, can you please provide a basic repository to reproduce the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants