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

Incorrect module loading in cluster mode with NODE_PATH #1146

Closed
Jokero opened this issue Apr 6, 2015 · 6 comments
Closed

Incorrect module loading in cluster mode with NODE_PATH #1146

Jokero opened this issue Apr 6, 2015 · 6 comments

Comments

@Jokero
Copy link

Jokero commented Apr 6, 2015

OS - Ubuntu 14.04.1 LTS
Node.js - 0.12.0
pm2 - 0.12.9

For example, I have two apps "pm2" and "main" with similar structure:

app.js
apps.json
lib/logger.js

app.js:

console.log('NODE_PATH=' + process.env.NODE_PATH);

require('lib/logger')();

var http = require('http');
http.createServer().listen(8080); // 8081 for "main" app

apps.json:

{
  "apps" : [{
    "name":      "pm2", // "main"
    "script":    "app.js",
    "exec_mode": "cluster_mode",
    "instances": 0
  }]
}

lib/logger.js:

module.exports = function() {
   console.log('logger from pm2 app'); // console.log('logger from main app');
};
  1. Run "pm2" app:
dmitry@dmitry:~/dev/pm2$ NODE_PATH=/home/dmitry/dev/pm2 pm2 startOrRestart apps.json

Logs:

pm2-0 (out): NODE_PATH=/home/dmitry/dev/pm2
pm2-0 (out): logger from pm2 app
pm2-1 (out): NODE_PATH=/home/dmitry/dev/pm2
pm2-1 (out): logger from pm2 app
pm2-2 (out): NODE_PATH=/home/dmitry/dev/pm2
pm2-2 (out): logger from pm2 app
pm2-3 (out): NODE_PATH=/home/dmitry/dev/pm2
pm2-3 (out): logger from pm2 app

Everything is good: logger was loaded from "pm2" directory.

  1. Run "main" app
dmitry@dmitry:~/dev/main$ NODE_PATH=/home/dmitry/dev/main pm2 startOrRestart apps.json

Logs:

pm2-0 (out): NODE_PATH=/home/dmitry/dev/pm2
pm2-0 (out): logger from pm2 app
pm2-1 (out): NODE_PATH=/home/dmitry/dev/pm2
pm2-1 (out): logger from pm2 app
pm2-2 (out): NODE_PATH=/home/dmitry/dev/pm2
pm2-2 (out): logger from pm2 app
pm2-3 (out): NODE_PATH=/home/dmitry/dev/pm2
pm2-3 (out): logger from pm2 app
main-4 (out): NODE_PATH=/home/dmitry/dev/main
main-4 (out): logger from pm2 app
main-5 (out): NODE_PATH=/home/dmitry/dev/main
main-5 (out): logger from pm2 app
main-6 (out): NODE_PATH=/home/dmitry/dev/main
main-6 (out): logger from pm2 app
main-7 (out): NODE_PATH=/home/dmitry/dev/main
main-7 (out): logger from pm2 app

NODE_PATH is correct, but logger was loaded from "pm2" directory. So previous value of NODE_PATH was used, not current

@jshkurti jshkurti self-assigned this Apr 6, 2015
@chylvina
Copy link

chylvina commented Apr 8, 2015

+1

1 similar comment
@tamtakoe
Copy link

tamtakoe commented Apr 8, 2015

+1

@jshkurti
Copy link
Contributor

jshkurti commented Apr 8, 2015

Bug confirmed. Working on it :)

@itsjustcon
Copy link

+1

@jshkurti
Copy link
Contributor

npm i -g git://github.com/Unitech/PM2#development should be fixed.
Can you try please ? :)

@Jokero
Copy link
Author

Jokero commented Apr 16, 2015

All is ok 👍 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants