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

the connection.handshake.address object is sometimes undefined #1042

Closed
thekiur opened this issue Oct 1, 2012 · 3 comments
Closed

the connection.handshake.address object is sometimes undefined #1042

thekiur opened this issue Oct 1, 2012 · 3 comments

Comments

@thekiur
Copy link
Contributor

thekiur commented Oct 1, 2012

io.sockets.on('connection', function(connection) {
  console.log(
    connection.handshake, // always present
    connection.handshake.address, // sometimes undefined
    connection.handshake.address.address // sometimes ReferenceError
  );
});

Thats pretty much it.
Im expecting connection.handshake.address.address to contain the IP address related to the client, but i sometimes randomly get a ReferenceError there, as connection.handshake.address seems to be undefined.

Node 0.8.x
Socket.IO latest

@ghost
Copy link

ghost commented Nov 4, 2012

I have a same problem. And I use clusters + redis to sync sockets between processes. In app without it - this problem wasn't present.

I came up with a way to prevent:

var socket_ip = (socket.handshake != undefined && socket.handshake.address != undefined) ? socket.handshake.address.address : "IP_ERROR";

but it isn't a solution. sometimes my app has a dead-sockets in some processes, but in some other they aren't. So this is just a way to prevent crashing your app.

It may be because there are a lot "client not handshaken" so that's why socket.handshake is undefined?

@btccointicker
Copy link

hashi101, many thanks for this fix. Just giving it a try now, hopefully it will stop my app from crashing :-)

@btccointicker
Copy link

Worked like a charm. Thank you sir!

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

No branches or pull requests

2 participants