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

Fix: immediate recompilation #256

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

rluba
Copy link

@rluba rluba commented Mar 16, 2021

We noticed that restarting the process upon changes did not work reliably if the process was still in the middle of compilation when the change occurred.

In that situation it seems like disconnecting from the child before sending the SIGTERM causes the child process to freeze. On my machine (MacOS 10.15, node.js 14.16.0) the child kept spinning at 100% CPU load, but did not react to SIGTERM – neither the one sent by ts-node-dev nor any signal sent manually.

Not disconnecting from the child before killing it resolves the issue. It has the added advantage of showing why restarting may take longer than expected – you still receive the old child’s log output and see, eg., when the old compilation finally finishes.

While investigating the cause of the hang, I also noticed that ts-node-dev read the content of every changed file twice (and much earlier than needed). This PR also fixes that.

src/compiler.ts Outdated
const starTime = new Date().getTime()

const fileName = params.compile
const code = params.code || fs.readFileSync(fileName, 'utf-8')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the passed params.code, if available, to avoid reading the file twice. We also do it much later to avoid reading it if it isn’t necessary.

@@ -81,6 +81,10 @@ If you have an issue, please create one. But, before:
- try to run it with `--debug` flag and see the output
- try to make create repro example

## Building

Run `tsc --build tsconfig.build.json` to transpile this project.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

… just because I had to look and experiment for a while to figure out how to compile this project.

@Narretz
Copy link

Narretz commented Aug 14, 2021

@wclr what do you think about this PR? Looks like 2 nice improvements without a lot of code changes.

@jasrusable
Copy link

+1 here. We are facing the same issue of high CPU usage occasionally as @rluba mentioned. Would be great if we could get this fixed ASAP.

src/compiler.ts Outdated
const starTime = new Date().getTime()

const fileName = params.compile
const code = params.code || fs.readFileSync(fileName, 'utf-8')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this line even needs to still be here because the 'code' local variable is not actually used.

Copy link

@mafo5 mafo5 Oct 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the line as requested because the code was actually not used

@mafo5
Copy link

mafo5 commented Oct 20, 2021

@wclr Any things we need to fix which prevents this PR from being merged?

@m-abboud
Copy link

m-abboud commented Oct 20, 2021

BTW we've been using a version with this fix since August and initially it correctly restarted every time you made a change. But recently it's started not restarting sometimes when you make changes in quick succession (but still better than without this fix). Maybe related to a mac os update or node version update is my wild guess.

Would recommend merging this in still since it at least improves behavior a little and has not broken anything after 2 months of using it.

@mafo5
Copy link

mafo5 commented Dec 13, 2021

@wclr any progress on this PR? What is missing?

@wiktor-obrebski
Copy link

It's quite painful and can bring a lot of confusion for big projects with long compilation time (like one I work in).
Can it be released?

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

Successfully merging this pull request may close these issues.

None yet

6 participants