remoteAddresse undefined when connecting from nodejs client (only on nodejs 0.10.x) #176

Closed
alaa-eddine opened this Issue Jun 5, 2013 · 11 comments

6 participants

@alaa-eddine

when connecting to an engine.io server from engine.io-client on nodejs 0.10 , the client IP is undefined

to reproduce the behaviour here is a simple code

//server

var engine = require('engine.io')
  , http = require('http').createServer().listen(3000)
  , server = engine.attach(http)

server.on('connection', function (socket) {
   // reading client IP
    console.log('IP = ', socket.request.connection.remoteAddress);

    socket.on('message', function () { });
    socket.on('close', function () { });
});

//client
var socket = require('engine.io-client')('ws://localhost:3000/');
socket.onopen = function () {
    socket.onmessage = function (data) { };
    socket.onclose = function () { };
};

this code will give undefined addresse on nodejs 0.10.x and the client IP on nodejs 0.8.x

what's strange is that when the client is a browser, the remoteAddress will be set on both nodejs 0.10.x and 0.8.x

(for browser test use the example on engine.io repository the above example will not open in browser)

this behaviour depends on the server side nodejs version.
running the client with nodejs 0.10.x or 0.8.x don't change anything

@rauchg

@alaa-eddine did you find out anything else? Are you starting hte client and server in the same process or different processes? Does that change anything?

@rauchg

Also @isaacs any insight into how 0.10 could have broken this?

@alaa-eddine

@guille client and server are on different processes, I'll try tomorrow with a single process and post back the result here.

@alaa-eddine

sorry for the delay.
tested with server and client on the same process, and I have the same behaviour !

whre in your code do you set socket.request.connection.remoteAddress ?

@3rd-Eden

Had the same issues. I got the feeling that the remoteAddress is removed after the original connection is closed. Which kinda makes sense, as the initial request is made by a polling request and closed before a connection event is triggered.

I got around this by caching the remoteAddress & port on a different property on the request object;

https://github.com/3rd-Eden/primus/blob/master/transformers/engine.io/server.js#L46-L53

@alaa-eddine

@3rd-Eden this is what I was looking for ! I'll give it a try thank's :)
btw, why you dont submit a pull request to @guille ?

@rauchg

I don't think it's our job to be caching it. It'd make more sense to maintain node's behavior

@jigneshnavsoft

i am not getting socket.request.connection.remoteAddress

@prawnsalad

Any update on this? I'm having the issue here, crippling some users of the Kiwi IRC nodejs project.
Users report it happening when behind a reverse proxy, but I can't see any common factor between the users that the issue occurs with. request.remoteAddress is undefined.

Is there any other way for us to get the clients IP?

@rase-

Based on the conversation, I think this could be closed.

@rauchg rauchg closed this May 24, 2014
@prawnsalad

Now this issue is closed, what is the recommended way to get the remote clients address? Just closing it doesn't help anybody with the issue.

Do we have to manually manage remoteAddress ourselves as @3rd-Eden has gone about it? If so, it seems a very round about way just to get a clients address for a web service.

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