strongloop / strong-agent

Profile, control, and monitor Node.js processes and clusters
http://strongloop.com/node-js/devops-tools/
Other
62 stars 9 forks source link

Error while running slc run in harmony mode #6

Closed evanhuang8 closed 9 years ago

evanhuang8 commented 9 years ago

I am trying to run my application locally via slc run, but since the app uses ES6 features, I have to run it in harmony mode, so I did:

node --harmony /usr/local/bin/slc run server.js

However, the following error pops up:

TypeError: undefined is not a function
    at Agent.strongTraceLink (/usr/local/lib/node_modules/strongloop/node_modules/strong-agent/lib/agent.js:685:10)
    at /usr/local/lib/node_modules/strongloop/node_modules/strong-agent/lib/probes/mysql.js:49:11
    at Object.eval [as forward] (eval at recompile (/usr/local/lib/node_modules/strongloop/node_modules/strong-agent/lib/proxy.js:237:15), <anonymous>:3:6)
    at Connection.eval [as query] (eval at wrap (/usr/local/lib/node_modules/strongloop/node_modules/strong-agent/lib/proxy.js:193:20), <anonymous>:3:21)
    at /Users/xxx/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:91:16
    at Object.tapHandler (/Users/xxx/node_modules/sequelize/node_modules/bluebird/js/main/finally.js:88:23)
    at tryCatch1 (/Users/xxx/node_modules/sequelize/node_modules/bluebird/js/main/util.js:45:21)
    at Promise._callHandler (/Users/xxx/node_modules/sequelize/node_modules/bluebird/js/main/promise.js:571:13)
    at Promise._settlePromiseFromHandler (/Users/xxx/node_modules/sequelize/node_modules/bluebird/js/main/promise.js:581:18)
    at Promise._settlePromiseAt (/Users/xxx/node_modules/sequelize/node_modules/bluebird/js/main/promise.js:713:18)

What's wrong here?

sam-github commented 9 years ago

I recommend looking at https://iojs.org/en/es6.html, particularly

On Node.js™@0.12.x (V8 3.28+), the --harmony runtime flag enables all completed, staged and in progress ES6 features together, in bulk (with the exception of proxies which are hidden under --harmony-proxies). This means that some really buggy or even broken [...]

If I can repro, I'll take a quick look, and if there is an easy tweak, I'll make it, but we don't test with --harmony, and I'm not sure we will commit to supporting it.

Either way, I would STRONGLY recommend against using --harmony. If you are using io.js, use only es6 features that are available in "strict mode", and if you are on an earlier node, use https://www.npmjs.com/package/6to5.

sam-github commented 9 years ago

fwiw, I cannot repro with https://github.com/strongloop/express-example-app, and a locally installed supervisor:

% node --harmony ./node_modules/.bin/sl-run server.js 
INFO strong-agent v1.6.21 profiling app 'express-example-app' pid '4454'
INFO strong-agent[4454] started profiling agent
INFO supervisor reporting metrics to `internal:`
supervisor running without clustering (unsupervised)
Listening on port: 3000
evanhuang8 commented 9 years ago

Thanks for the prompt reply.

Here is the slc -v output:

strongloop v4.0.5 (node v0.12.0)
├── strong-arc@1.4.4 (889bc42)
├── strong-build@2.0.2 (3221b91)
├── strong-deploy@2.2.2 (13baab4)
├── strong-pm@4.3.1 (45d254a)
├── strong-registry@1.1.5 (f46e58f)
├── strong-start@1.2.0 (e59f8b5)
├─┬ strong-supervisor@2.0.2 (610a578)
│ └── strong-agent@1.6.2
├── generator-loopback@1.10.1 (eae270c)
├── node-inspector@0.7.4
└── nodefly-register@0.3.3

When I use node /usr/local/bin/slc run server.js, it instead gives me error on the lines of the generator function:

/Users/xxx/.app/server.js:8
  co(function*() {
             ^
SyntaxError: Unexpected token *
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Object.<anonymous> (/usr/local/lib/node_modules/strongloop/node_modules/strong-supervisor/bin/sl-run.js:76:19)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

Which is expected.

I am wondering if this is an account related issue? I am using a trial account locally (OS X), but I have ran slc strongops and setup the credentials.

I suppose worst case I can just use babel to compile it back.

rmg commented 9 years ago

@evanhuang8 Based on the error, I don't think it's an account issue. It looks like something about the app's use of ES6 is breaking a this binding inside the agent somehow. Is the app source public or are you able to reduce it to a small example that fails?

evanhuang8 commented 9 years ago

Unfortunately the source code is private, but per your note I did some trace and it seems like it's sequelize package that is causing problems, which I don't think actually has to do with the harmony stuff?

evanhuang8 commented 9 years ago

Did a bit more debugging, so in the function

Agent.prototype.strongTraceLink = function(dbId, query, args){
  var linkName = dbId + ' ' + query;
  var callbackIndex = -1;
  for(callbackIndex = args.length - 1; callbackIndex >= 0; callbackIndex--){
    if (typeof args[callbackIndex] === 'function') {
      args[callbackIndex] = this.transactionLink(linkName, args[callbackIndex]);
      break;
    }
  }
  if (callbackIndex === -1) {
    console.log(this);
    console.log(args);
    args.push(this.transactionLink(linkName, function(){}));
  }
}

The args is actually like this:

{ '0': 'SET time_zone = \'+00:00\'' }

instead of an array, which is then causing the undefined is not a function problem

evanhuang8 commented 9 years ago

It seems like whenever I am trying to sync the table via sequelize, it gives me the error; if I simply establish a db connection, no errors will occur. Would this be an issue for the mysql tracing in the strong agent?

rmg commented 9 years ago

@evanhuang8 thanks for the effort. I think I found the root of the problem and we're working on a fix.

evanhuang8 commented 9 years ago

@rmg awesome thanks!

sam-github commented 9 years ago

Should be fixed in strong-agent@1.6.3, @evanhuang8, can you try? Thanks for the trouble-shooting.

My comments about --harmony stand! Consider using io.js, or 6to5.

evanhuang8 commented 9 years ago

@sam-github it works now, thanks for the good work!

As for --harmony, all I really need is generators (and yield), would io.js be a good fit out of the box (for production)? I could use 6to5 for my codebase, but how would I deal with external dependencies (like koa.js, which still runs on generators)

rmg commented 9 years ago

For using generators, in order of "production readiness", I would say:

  1. node-v0.10.39 + 6to5/babel/etc.
  2. iojs
  3. node --harmony