Sitelet https://github.com/nodejs/node/issues/10976
Skip to content

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

Description

@pkoretic

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)
})

Activity

  1. added
    domainIssues and PRs related to the domain subsystem.
    netIssues and PRs related to the net subsystem.
    httpIssues and PRs related to the http subsystem.
    and removed
    domainIssues and PRs related to the domain subsystem.
    on Jan 24, 2017
  2. bnoordhuis commented on Jan 24, 2017

    @bnoordhuis
    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.

  3. pkoretic commented on Jan 25, 2017

    @pkoretic
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues and PRs related to the http subsystem.invalidIssues and PRs that are invalid.netIssues and PRs related to the net subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions