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

socket._handle.fd invalid when domain is used #10976

Closed
pkoretic opened this issue Jan 24, 2017 · 2 comments
Closed

socket._handle.fd invalid when domain is used #10976

pkoretic opened this issue Jan 24, 2017 · 2 comments
Labels
http Issues or PRs related to the http subsystem. invalid Issues and PRs that are invalid. net Issues and PRs related to the net subsystem.

Comments

@pkoretic
Copy link

pkoretic commented Jan 24, 2017

Version: 7.4
Platform: Linux DEV-PC 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Subsystem: http

This happens from node 4.x to 7.x as far as I've tested on MacOS and Ubuntu/Arch Linux with older/newer stack and software.

Example attached, shows that using domain name for HTTP request results in invalid socket _handle.fd

Usine createConnection directly gives a valid fd in both cases

I know that file descriptors in node are like black sheeps but is there something else that needs to be done to get a valid socket file descriptor or is this a genuine bug?

const http = require('http')
const net = require('net')

// this doesn't give valid fd handle
const r1 = http.get({ hostname: 'www.google.hr', port: 80 })

r1.on('socket', function(s)
{
    console.log("socket fd invalid", s._handle.fd)
})

// this does give valid fd handle, notice that ip is used instead of domain name
const r2 = http.get({ hostname: '213.202.89.187', port: 80 })

r2.on('socket', function(s)
{
    console.log("socket fd valid", s._handle.fd)
})

// this gives valid handle
const s1 = net.createConnection({ host: "www.google.com", port:80 }, function()
{
    console.log("socket fd valid:", s1._handle.fd)
})

// this gives valid handle
const s2 = net.createConnection({ host: "213.202.89.187", port:80 }, function()
{
    console.log("socket fd valid:", s2._handle.fd)
})
@mscdex mscdex added domain Issues and PRs related to the domain subsystem. net Issues and PRs related to the net subsystem. http Issues or PRs related to the http subsystem. and removed domain Issues and PRs related to the domain subsystem. labels Jan 24, 2017
@bnoordhuis
Copy link
Member

Not a bug - and it couldn't be, socket._handle.fd is internal and just for debugging.

What happens is that the DNS query is still in flight and the TCP connection hasn't been set up yet. Listen for the 'connect' event on the socket and only then inspect the .fd property.

@bnoordhuis bnoordhuis added the invalid Issues and PRs that are invalid. label Jan 24, 2017
@pkoretic
Copy link
Author

in #8974 _handle.fd is presented as it is expected to be used even though it is internal

and this solution is a no go when one wants to set TCP_KEEPINTVL and TCP_KEEPCNT on that socket since it has to be set before connect so that connect is not hanging in specific cases (https://github.com/hertzg/node-net-keepalive)

I guess I can only resolve domain up front and then make a request as a workaround, yuck
Thanks nevertheless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem. invalid Issues and PRs that are invalid. net Issues and PRs related to the net subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants