ts-node-dev: Infinite loop, 100% CPU
In ts-node-dev-hooks, the compile function runs this:
waitForFile(compiledPath + '.done')
which ends up in the function waitForFile
. This runs an infinite loop as the file is never created. This is the block:
var waitForFile = function(fileName) {
var start = new Date().getTime()
while (true) {
const exists = execCheck
? execSync(['node', checkFileScript, '"' + fileName + '"'].join(' '), {
stdio: 'inherit'
}) || true
: fs.existsSync(fileName)
if (exists) {
return
}
var passed = new Date().getTime() - start
if (timeThreshold && passed > timeThreshold) {
throw new Error('Could not require ' + fileName)
}
}
}
exists
is always false, execCheck
is false. timeThreshold
is 0
Unless I misunderstand the code, it also seems terribly “spinny”. Why don’t we use file watchers, or something like 100ms polling? We should also bail out after a timeout - e.g. no produced file within say 10 seconds or so. Why is timeThreshold
0?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 8
- Comments: 19 (6 by maintainers)
This is definitely still an issue, seeing it daily on our project using
ts-node-dev
and it’s always a git checkout that seems to trigger it.@wclr I did some digging on this and the issue seems to be related to
fork
. I built a minimal repro: https://gist.github.com/LucasPickering/f1568762a2a774923f15a8f6b5781c87If you clone that repo and do
npm install
, you should see these results:This runs with just
ts-node
, and the output is:and it quickly exits, which is what we’d expect. With
ts-node-dev
though…output looks like:
and then it just hangs. I tried downgrading TypeScript to 4.1.2 (and 4.0.0 for good measure) and still saw the issue, so I’m not sure how long this has been around. Would you mind taking another look at this? Please let me know if there’s any other info I can give that would be helpful.
I ran into this as well. For me it seemed to be related to node 10.16.0. Downgrading to 10.15.x resolved it.