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

Trace.fromRequest in Trace.js fails when using Unix Socket instead of TCP/IP Network Socket #36

Closed
radkins3141 opened this issue Sep 4, 2015 · 4 comments

Comments

@radkins3141
Copy link

In Trace.fromRequest in the file lib/trace.js, a variable called 'host' is unprotected when function call 'request.socket.address()' returns null, resulting in an error later when host.address is dereferenced during the construction of a new Endpoint. This is because, within the request.socket.address function, a native code function called 'getsockname' is undefined on the internally used 'request.socket._handle' object when associated with a Unix Socket. In contrast, getsockname is properly defined (by node.js) and can be found when the request is associated with a TCP/IP socket. A sample fix for Trace.fromRequest could be to protect the 'host' variable with a slight modification to the current code similar to the following:

var hostAddress = null;
if (request.socket && request.socket.address) {
   hostAddress = request.socket.address();
}
// Note hostAddress can be set to null when using a Unix instead of a TCP/IP Socket
var host =  hostAddress ? hostAddress : {address: '127.0.0.1', port: 80};

[ Please note I'm using node v0.10.26 in an Ubuntu 15.04 environment. Thank's in advance for looking at this issue. ]

@suryatech
Copy link
Contributor

@radkins3141
Thanks for providing context into #31

#35 is relevant to the above issue. Please have a look at it.

@radkins3141
Copy link
Author

Hi Surya,

The problem with the work-around for issue #35 seems to be that on line
262, the variable 'host' can still be null. In this case, dereferencing it
to access the 'address' attribute will fail. There are several ways to fix
this, including this simple way:

var host = (request.socket && request.socket.address ?
(request.socket.address() ? request.socket.address() : {address:
'127.0.0.1', port: 80})
: {address: '127.0.0.1', port: 80});

Bob

On Sat, Sep 5, 2015 at 8:37 AM, Surya P [email protected] wrote:

@radkins3141 https://github.com/radkins3141
Thanks for providing context into #31
#31

#35 #35 is relevant to the
above issue. Please have a look at it.


Reply to this email directly or view it on GitHub
#36 (comment).

@suryatech
Copy link
Contributor

@radkins3141
In the case of a Unix socket, is request.socket.address undefined or does it return null ?
If the latter is true, your case makes perfect sense and we should make changes to address it.

@radkins3141
Copy link
Author

on Linux -- at least on node v0.10.26 and Ubuntu 15.04 --
'request.socket.address' does return null when using a unix socket

On Wed, Sep 9, 2015 at 10:10 AM, Surya P [email protected] wrote:

@radkins3141 https://github.com/radkins3141
In the case of a Unix socket, is request.socket.address undefined or does
it return null ?
If the latter is true, your case makes perfect sense and we should make
changes to address it.


Reply to this email directly or view it on GitHub
#36 (comment).

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