wankdanker / node-discover

Automatic and decentralized discovery and monitoring of nodejs instances with built in support for a variable number of master processes, service advertising and channel messaging.
229 stars 59 forks source link

Encryption issue #3

Closed aledbf closed 11 years ago

aledbf commented 11 years ago

I don't know if this an error or the desired behavior for node-discover:

I have at least 2 apps with multiple instances with different keys (the rest of the conf is the same). I get this error:

TypeError: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
crypto.js:287:27 • Cipher.final
node_modules/node-discovery/lib/streams.js:168:21 • _transform
....

I know that if I set different ports this works fine but if that's the case i need one additional port per app instead of just one for discovery? Thanks.

wankdanker commented 11 years ago

Interesting. I hadn't actually tested this, but my original intent was to be able to use different keys while on the same port.

I had assumed that one instance decrypting with the wrong key would throw an error and that I would catch that error. It seems that since I did not actually test all of my assumptions that I never ended up try/catching or binding to an error event in the decrypt function (https://github.com/wankdanker/node-discover/blob/master/lib/network.js#L176).

I think we should be able to fix this pretty easily.

wankdanker commented 11 years ago

What version of node are you using? I just tested this as is and it works as expected without any additional error checking.

I'm using node v0.10.13

aledbf commented 11 years ago

Hi, I tried v0.10.13 and v0.10.16

To reproduce the error:

key1.js

var Discovery = require('node-discovery').Discovery;

var c = new Discovery({
  key: 'key1',
  weight:1
});

c.on('promotion', function() {
  console.log('I was promoted.');
});

c.on('demotion', function() {
  console.log('I was demoted.');
});

c.on('master', function(obj) {
  console.log('New master.');
});

key2.js

var Discovery = require('node-discovery').Discovery;

var c = new Discovery({
  key: 'key2',
  weight:1
});

c.on('promotion', function() {
  console.log('I was promoted.');
});

c.on('demotion', function() {
  console.log('I was demoted.');
});

c.on('master', function(obj) {
  console.log('New master.');
});
wankdanker commented 11 years ago

Oh, it looks like you are using node-discovery which is a fork of this project by @skeggse. A lot of stuff has changed on that fork and is beyond me to fix it.

If you install with npm install node-discover, it will probably work for you. But will be missing whatever features @skeggse has added in node-discovery.

aledbf commented 11 years ago

I'm sorry, my fault. Like you said, your version works fine (and the error is in the fork)

wankdanker commented 11 years ago

No worries! Cheers!