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

Syntax error in a file crashes babel-watch #32

Closed
steelbrain opened this issue Nov 30, 2016 · 3 comments
Closed

Syntax error in a file crashes babel-watch #32

steelbrain opened this issue Nov 30, 2016 · 3 comments

Comments

@steelbrain
Copy link
Contributor

Not only it crashes but also triggers a bug in Node.js making it gets stuck at 100% cpu usage.

I get infinite of this in dtrace of the process with 100% cpu usage

dtrace: error on enabled probe ID 2134 (ID 318: syscall::read:return): invalid kernel access in action #12 at DIF offset 92

I also get this in my log

Error: Cannot find module 'our-storage'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/steel/w/d/triangle/packages/container/lib/projects.js:3:1)
    at Module._compile (module.js:570:32)
    at babelWatchLoader (/Users/steel/w/d/triangle/node_modules/babel-watch/runner.js:50:13)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/steel/w/d/triangle/node_modules/babel-watch/runner.js:61:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
fs.js:786
    return binding.writeBuffer(fd, buffer, offset, length, position);
                   ^

Error: EPIPE: broken pipe, write
    at Error (native)
    at Object.fs.writeSync (fs.js:786:20)
    at handleFileLoad (/Users/steel/w/d/triangle/node_modules/babel-watch/babel-watch.js:273:27)
    at handleFileLoad (/Users/steel/w/d/triangle/node_modules/babel-watch/babel-watch.js:170:7)
    at ChildProcess.app.on (/Users/steel/w/d/triangle/node_modules/babel-watch/babel-watch.js:263:5)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at process.nextTick (internal/child_process.js:744:12)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

I'm on macOS Sierra, with Node v6.9.1 and babel-watch v2.0.3

@kmagiera
Copy link
Owner

Thanks @steelbrain for reporting and sorry for not getting back to you earlier.

Would you be able to provide a more specific repro scenario as I couldn't reproduce the issue only based on what you've provided. Here is what I tried:

  1. Create simple project with app.js file with the following content:
console.log("Hello");
  1. Run babel-watch app.js
  2. See it runs correctly (prints Hello)
  3. Update app.js and remove last quotation mark to introduce a syntax error
  4. Get the following error printed:
Babel compilation error SyntaxError: /private/tmp/kaka/app.js: Unterminated string constant (1:12)
> 1 | console.log("Hello)
  1. Update app.js again to get rid of the syntax error
  2. See babel-watch restart again and runs the app correctly

@steelbrain
Copy link
Contributor Author

Hi @kmagiera

I cannot provide any solid info any time soon but to tell you what fixed the issue for me, I basically wrapped all the fs.*Sync calls with a try { fs.*Sync(...) } catch (_) { process.exit() }

It not only fixed the error for me, but also fixed the scenarios where a babel-watch spawned process will be backgrounded and will take 100% cpu printing only the syscall read kernel error I posted in my first post. I hope this gives you an idea of what the problem might be, my random guess was that the spawned child process was writing to an fd created by the parent and when the parent process crashes it causes a deadlock for the child.

@kmagiera
Copy link
Owner

@steelbrain thanks anyways. I think that your issue might have been resolved by #38 merged earlier today which basically catches and ignores "EPIPE". That error could've been thrown when child process have died (perhaps due to syntax error) and make parent process hang in trying to write to the pipe. Would you be able to try the newest version and see if you're still having this problem? If so feel free to reopen the issue

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

2 participants