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 · 3 comments
Open

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

Stono opened this issue Dec 22, 2023 · 3 comments
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?

@Bruno-Meowtel
Copy link

Bruno-Meowtel commented Oct 1, 2024

We are using Nuxt.js 3.x and I had a similar issue in our entry.mjs file.

@Stono's fix resolved the issue, but it'd be awesome if this was working right out of the box :)

@Rigo-m
Copy link

Rigo-m commented Oct 13, 2024

We are using Nuxt.js 3.x and I had a similar issue in our entry.mjs file.

@Stono's fix resolved the issue, but it'd be awesome if this was working right out of the box :)

Hi Bruno, how did you fix it in nuxt 3?

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

4 participants