elad / node-cluster-socket.io

Writeup on how to make node.js cluster and socket.io play nice
421 stars 63 forks source link

connection.remoteAddress is undefined #7

Closed DefrenneD closed 8 years ago

DefrenneD commented 9 years ago

Hi everybody,

I'm using nginx as a reverse-proxy and connection.remoteAddress is undefined.

var server = net.createServer(function(connection) {
...
connection.remoteAddress //undefined
...
}).listen('/tmp/node.sock');

Do you have any ideas how I could get the IP ?

When i'm testing without nginx everything is fine.

barisusakli commented 9 years ago

See this thread https://github.com/indutny/sticky-session/issues/6 I don't think there is a simple solution yet. I ended up dropping node cluster and spawning workers on different ports and load balancing with nginx.

elad commented 9 years ago

Is the problem here that the source address is set in a header by nginx which requires reading data before being able to tell which worker to pass the connection to?

barisusakli commented 9 years ago

@elad yes exactly.

wzrdtales commented 9 years ago

Pull request fixing this issue is open https://github.com/indutny/sticky-session/pull/17, you could look into this to fix your problems.

elad commented 9 years ago

I don't like the idea of peeking into a packet and parsing it... :/

wzrdtales commented 9 years ago

@elad Then make a better suggestion... I tried several other ways, but the only way it worked was getting it directly on the TCP Layer and putting it right back there.

At least this is exactly the same thing you would do if you would let make NGINX the balancing or HAProxy instead. It processes all packets, manipulating them and then sending them to node. But you don't send it over the Network Layer again, you just push it back to the read queue.

If you really have an Idea that works, I would be absolutely pleasured if you would tell me. As I already pointed out in the pull request, I don't have a problem with getting a packet and parsing it myself. There is nothing wrong with this, but I have a problem with relying on a function which behavior changes regurlarly often. And if there is a possibility that this functionality can be archived easier, this would be great.

"If there is any other way to accomplish this, I would be pleased if you would tell me :) Accessing this component is not really beautiful, as it changes often and is not stable and/or backward compatible. That is also the reason why this fix only works in the rnage of 0.9.7 to 0.11."

elad commented 9 years ago

I don't have a better idea at the moment. Once I have some free time to look into it I hope I will, though. :)

elad commented 8 years ago

Closing for the same reason as #15.

davidolen commented 7 years ago

@barisusakli

Just interested, when you were "dropping node cluster and spawning workers on different ports", did you start each worker process using a separate command "node app.js"? Or did you use another module to create and manage the worker processes? Also, what is the performance (and reliability)?

Thanks!