镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Make http.request work offline #17641

Description

@zvxayr

Node Version: v8.9.3
Platform: Windows 8 64-bit

I am trying to make a client communicate to a server on the same device offline through http but only get this error instead:

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo ENOENT localhost:8000
    at Object._errnoException (util.js:1024:11)
    at errnoException (dns.js:55:15)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)

I ran the client code online and it works so I suspect that http.request does not work without internet connectivity.

Activity

  1. changed the title [-]Make http.get work offline[/-] [+]Make http.request work offline[/+] on Dec 13, 2017
  2. Trott commented on Dec 13, 2017

    @Trott
    Member

    I suspect that http.request does not work without internet connectivity.

    That is incorrect.

    Without more information (like the code you are running), it is difficult to say what is causing the problem. However, judging from your error message, I'd guess that you are setting the host or hostname option to localhost:8000 rather than localhost.

  3. Trott commented on Dec 13, 2017

    @Trott
    Member

    (By the way, if you think it might be helpful to have others look at your code, feel free to post your code and a question as an issue in the https://github.com/nodejs/help.)

  4. addaleax commented on Dec 13, 2017

    @addaleax
    Member

    It kind of feels like something (dns?) should throw a more helpful error in this case?

  5. Trott commented on Dec 13, 2017

    @Trott
    Member

    It kind of feels like something (dns?) should throw a more helpful error in this case?

    Perhaps. What might the more helpful error look like? It does seem that ENOENT isn't the right error and I'd expect something more like EAI_NONAME or Node.js's non-standard ENOTFOUND.

    I guess it would help to know the code that is causing the error so we can be sure of what the problem is to make sure the error message provides correct clues as to the underlying issue.

  6. addaleax commented on Dec 13, 2017

    @addaleax
    Member

    Mh, the part that I’m not sure about: Can a string like localhost:8000 ever successfully resolve? If not, something in the error message that says “invalid hostname” or so would probably be great?

  7. gireeshpunathil commented on Dec 13, 2017

    @gireeshpunathil
    Member

    I tried the suspected sequence in windows, but for both:

    require('http').request({host: 'localhost:8000'})

    and

    require('http').request({hostname: 'localhost:8000'})

    I get this sequence

    Error: getaddrinfo ENOTFOUND localhost:8000 localhost:8000:80
        at errnoException (dns.js:55:10)
        at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:97:26)
    

    that is different from what was reported. So probably root cause is something else?

  8. zvxayr commented on Dec 13, 2017

    @zvxayr
    Author

    The code that I ran is:

    http.request({
        host: 'localhost',
        port: '8000',
        path: '/',
        method: 'GET'
    }, res => {
        res.setEncoding('utf8');
    
        res.on('data', data => {
            console.log(data);
        });
    }).end()

    and it does result in the error that I stated above when offline but succeeds when I connect to a wifi.

  9. gireeshpunathil commented on Dec 13, 2017

    @gireeshpunathil
    Member

    Tried in mac, and got this result, which looks correct. I don't have a windows box where I have rights to unplug net, but will see.

    #node h.js 
    events.js:183
          throw er; // Unhandled 'error' event
          ^
    
    Error: connect ECONNREFUSED 127.0.0.1:8000
        at Object._errnoException (util.js:1024:11)
        at _exceptionWithHostPort (util.js:1046:20)
        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
    #
    
  10. gireeshpunathil commented on Dec 13, 2017

    @gireeshpunathil
    Member

    tried in windows too, but the result is same as mac - it works as expected. Looks like a peculiar characteristics in your system. One of the step worth trying is to isolate (scope-in / scope-out) node from the issue by trying: (i) a browser client vs node server, (ii) browser client vs. non-node server, and their complements.

  11. zvxayr commented on Dec 13, 2017

    @zvxayr
    Author

    by the way, I am running a node server that listens on port 8000.

    entering http://localhost:8000 on my browser works fine, both online and not.

  12. gireeshpunathil commented on Dec 13, 2017

    @gireeshpunathil
    Member

    thanks. what does

    require('dns').lookup('localhost', (e, a) => {console.log(a)})

    output, with wifi off?

  13. zvxayr commented on Dec 13, 2017

    @zvxayr
    Author

    thanks.
    The output is: 127.0.0.1

    I tried to reproduce the error on a different device (also windows) with the same node version, then the same error is thrown with wifi off

  14. gireeshpunathil commented on Dec 13, 2017

    @gireeshpunathil
    Member

    thanks for the info. let me investigate further with exact windows and node versions

  15. gireeshpunathil commented on Dec 13, 2017

    @gireeshpunathil
    Member

    also ping @nodejs/collaborators for pointers.

  16. 9 remaining items

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions