tststs / atom-ternjs

JavaScript code intelligence for atom with tern.js and autocomplete-plus
MIT License
628 stars 76 forks source link

100% CPU usage after file close #352

Closed qwelias closed 5 years ago

qwelias commented 5 years ago

Recently js-hyperclick package began to require hyperclick to be installed.

I'm not who to blame but if hyperclick is enabled then atom-ternjs-server-worker.js's CPU utilization goes to 100%

I'd like to profile it, but am not sure how to specify exec flags to run it with --inspect so I can attach DevTools

qwelias commented 5 years ago

My initial assumption regarding hyperclick was incorrect.

Example .tern-project:

{
  "ecmaVersion": "7",
  "libs": [],
  "loadEagerly": [],
  "dontLoad": [],
  "plugins": {
    "doc_comment": true,
    "node": {
      "dontLoad": "",
      "load": "",
      "modules": ""
    },
    "node_resolve": {},
    "modules": {
      "dontLoad": "",
      "load": "",
      "modules": ""
    },
    "commonjs": {}
  }
}

Steps to reproduce:

  1. open Atom
  2. open any js file
  3. require a lib and try to see it's autocompletions
  4. close opened file
  5. look at cpu load

After just a few seconds of profiling the worker you can see that process._fatalException @internal/bootstrap/node.js:444 eats around 45% of process time because it gets bombarded with errors. Error stack:

Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
    at process.target.send (internal/child_process.js:627:16)
    at process.<anonymous> (/home/qwelias/.atom/packages/atom-ternjs/lib/atom-ternjs-server-worker.js:119:11)
    at process.emit (events.js:182:13)
    at process._fatalException (internal/bootstrap/node.js:451:27)
qwelias commented 5 years ago

So what happens is on disconnect worker does process.kill() but does not specifies pid which is mandatory, then it just goes into infinite recursion

dpisklov commented 5 years ago

+1 here