docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

Dev server process not terminated by SIGINT when loader is stuck

Open Josh-Cena opened this issue 3 years ago • 8 comments

Have you read the Contributing Guidelines on issues?

Prerequisites

  • [X] I'm using the latest version of Docusaurus.
  • [X] I have tried the npm run clear or yarn clear command.
  • [X] I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • [ ] I have tried creating a repro with https://new.docusaurus.io.
  • [ ] I have read the console error message carefully (if applicable).

Description

If the loader has an infinite loop or any other bug that causes it to get stuck, the dev server keeps running even when SIGINT is sent.

Discovered while working on https://github.com/facebookincubator/infima/pull/219

Reproducible demo

No response

Steps to reproduce

  1. Init
  2. Change the options:
        docs: {
          sidebarPath: require.resolve('./sidebars.js'),
          // A hopeless infinite loop
          remarkPlugins: [() => { while (true); }],
        },
  1. yarn start
  2. Oh no, page stuck. SIGINT (Ctrl + C) to the rescue
  3. yarn start again
  4. [WARNING] Something is already running on port 3000. Probably:
  5. What? Run lsof -i tcp:3000 => The dev server process is indeed still running
  6. Use the force: kill -9 47874

Expected behavior

SIGINT should be able to stop the dev server

Actual behavior

It keeps running in the background and listening on port 3000. Probably the compile process is never hung properly...

Self-service

  • [X] I'd be willing to fix this bug myself.

Josh-Cena avatar Mar 22 '22 08:03 Josh-Cena

yes noticed that too

Note devServer.stop() returns a promise, maybe we just have a missing await?

slorber avatar Mar 23 '22 13:03 slorber

~~Oh, I think that's it!~~ No, changed it to devServer.stop().then(() => process.exit()); and the dev server is still stuck in the background

Josh-Cena avatar Mar 23 '22 13:03 Josh-Cena

weird, maybe the compiler should also be closed?

I've also noticed that sometimes yarn build + sigint wouldn't stop the process when building multiple locales, probably a similar issue :/

slorber avatar Mar 23 '22 13:03 slorber

@slorber process.on must be handled synchronously. I tried and found out that simply deleting the SIGINT handler would work (using WDS' default signal handler). Do you think we should bring in something like node-graceful or simply relying what's the default?

Josh-Cena avatar Mar 25 '22 00:03 Josh-Cena

🤷‍♂️ I don't know 😅 if it can work without any extra dependency I guess it's better

slorber avatar Mar 25 '22 09:03 slorber

hey, i got this problem, not sure why but single CTRL + C does not stop the process, i had to CTRL + C twice, but somehow the process still running in background (i got the same problem with port already in use when i start the server again).

Note: i use pnpm to run it, the project itself i just started to make it from template and nothing are changed, so i dont think the bug was from my end. my system is ubuntu 20 with Bodhi Linux distro 64-bit (arm64).

BanDroid avatar Apr 08 '24 20:04 BanDroid

It also happens to me occasionally (yarn1, macos), but I have never been able to find the cause 😅

slorber avatar Apr 11 '24 10:04 slorber

me too 👍

KnowledgeGarden avatar Jul 30 '24 22:07 KnowledgeGarden