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

Does not shutdown completely when run from the CLI #104

Open
ajotaos opened this issue Nov 6, 2020 · 27 comments
Open

Does not shutdown completely when run from the CLI #104

ajotaos opened this issue Nov 6, 2020 · 27 comments

Comments

@ajotaos
Copy link

ajotaos commented Nov 6, 2020

After running tsc-watch, on its own, from the CLI and trying to stop it, I'm always requiring an additional Ctrl+C.

Also, when used alongside concurrently, the SIGINT and SIGTERM is not being passed to the code in the onSuccess argument.

How do I tell tsc-watch, when run from the CLI, it should end the process and not remain hanging?

@gilamran
Copy link
Owner

gilamran commented Nov 7, 2020

That's interesting, as I encountered the same issue (Ctrl-C). never thought that the cause is tsc-watch.
But do you think that the SIGINT and SIGTERM is the same issue?

Can you organize a simple example repo to reproduce?

Thanks

@ajotaos
Copy link
Author

ajotaos commented Nov 7, 2020

Sure @gilamran

I really think tsc-watch is the responsible for the Ctrl+C. If you were to run tsc --watch and exit with Ctrl+C everything is fine but tsc-watch gets hold up. I'm using tsc --watch as reference since it mentions in the documentation that it's being used underneath.

You can test this separately with npm run watch:ts (tsc-watch hangs) and npm run watch:tsc (tsc --watch exits) or together with npm run watch:*. No matter how you run it or if you add more tasks, watch:ts is always the last one to log and remains exiting forever.

Not always do the SIGINT and SIGTERM handlers are called, it looks random but maybe there's something.

src/index.ts

console.log(`Script has started`);

const intervalId = setInterval(() => {
  console.log('tick');
}, 1000);

process.on('SIGINT', () => {
  clearInterval(intervalId);
  console.log(`Script has ended`);
  process.exit();
});

process.on('SIGTERM', () => {
  clearInterval(intervalId);
  console.log(`Script has ended`);
  process.exit();
});

tsconfig.json

{
  "compilerOptions": {
    "incremental": true,
    "target": "ES2020",
    "module": "CommonJS",
    "strict": true,
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "rootDir": "./src",
    "outDir": "./dist",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["./src/**/*"],
  "exclude": ["./node_modules"]
}

package.json

{
  "scripts": {
    "start": "concurrently --kill-others yarn:watch:*",
    "watch:ts": "tsc-watch --onSuccess \"node ./dist\" --noClear",
    "watch:tsc": "tsc --watch"
  },
  "dependencies": {},
  "devDependencies": {
    "concurrently": "5.3.0",
    "tsc-watch": "4.2.9",
    "typescript": "4.0.5"
  }
}

@ajotaos
Copy link
Author

ajotaos commented Nov 7, 2020

I have been continuing playing with it and sometimes even though I Ctrl+C it, the process has not been killed.

@gilamran
Copy link
Owner

gilamran commented Nov 7, 2020

Thanks! I'll look into it.

@gilamran
Copy link
Owner

gilamran commented Nov 9, 2020

I did a test (using your example code) and the Ctrl-C did terminate the process (Using SIGINT).
I'm using Mac. What's your OS?

@ajotaos
Copy link
Author

ajotaos commented Nov 9, 2020

I'm on Catalina 10..15.7 (the latest one), node 15.1.0, typescript 4.0.5 and tsc-watch 4.2.9.

When running watch:ts it's more subtle, there are hints for example, after Ctrl+C and the line prompt appearing on the terminal that if you push the up arrow button, instead of brining the previous like it will print ^[OA which happens when there's a process running.

It's more noticeable on the start script. In this case it happens the same as previously but the line prompt will not appear.

@gilamran
Copy link
Owner

gilamran commented Nov 9, 2020

I'm using the exact same versions, and Ctrl-C just stops the process... I don't see what you're describing...
What am I missing?

@ajotaos
Copy link
Author

ajotaos commented Nov 9, 2020

Does it work for you to video chat it on Zoom to check it out live?

@gilamran
Copy link
Owner

gilamran commented Nov 9, 2020

how can we do a private chat?

@ajotaos
Copy link
Author

ajotaos commented Nov 9, 2020

On GitHub? I didn't know it has that feature.

@gilamran
Copy link
Owner

gilamran commented Nov 9, 2020

I see that you're online... lets do zoom now

@gilamran
Copy link
Owner

gilamran commented Nov 9, 2020

@ajotaos
Copy link
Author

ajotaos commented Nov 9, 2020

I'm in @gilamran

@ajotaos
Copy link
Author

ajotaos commented Nov 9, 2020

Ok, after the Zoom meeting, it appears this issue is occurring only with the Yarn package runner. NPM works fine.

@gilamran
Copy link
Owner

gilamran commented Nov 9, 2020

I've pushed a branch test-kill please try it.

@ajotaos
Copy link
Author

ajotaos commented Nov 9, 2020

It worked on the single script watch:ts. The concurrently one start still requires a second Ctrl+C using yarn, on npm it works.

@jackHedaya
Copy link

jackHedaya commented Jan 11, 2021

I'm experiencing this issue as well, is there a patch?

@hamzadigi
Copy link

hamzadigi commented Nov 11, 2021

Having similar issue when ctrl + c with yarn

image

@divmgl
Copy link

divmgl commented Jul 28, 2023

We've had to move away from tsc-watch due to the number of loose process issues where exiting the process doesn't kill the running subprocess, so we have to manually kill the port after the fact. Also it sometimes just stops compiling at all.

@gilamran
Copy link
Owner

I've very sorry to hear that, maybe you can provide an example to reproduce the issue?

@Mujo
Copy link

Mujo commented Aug 14, 2023

We've had to move away from tsc-watch due to the number of loose process issues where exiting the process doesn't kill the running subprocess, so we have to manually kill the port after the fact. Also it sometimes just stops compiling at all.

same problem here.
when vscode is on Auto Attach mode with auto save, or using a debug terminal, each change on the file open a new debug process but don't close the previous one when using the --onSuccess with "npm start" or "node ./outDir".

@gilamran
Copy link
Owner

@Mujo I'm sorry but I don't understand your reproduction steps... can you give me clear instructions on how to reproduce this?

@Mujo
Copy link

Mujo commented Aug 14, 2023

Looks like something in most of the projects we use here in work is holding the process.
I tried to create a new project but couldn't reproduce yet. when i find it i will post here again.

@vimtor
Copy link

vimtor commented Mar 26, 2024

I'm facing the same issue using Turborepo.

@divmgl
Copy link

divmgl commented Mar 26, 2024

Hey all, tsx does not have any of these issues. It also has a watch mode. https://github.com/privatenumber/tsx

@gilamran
Copy link
Owner

Is anyone can provide a simple reproduction repo.?

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

8 participants