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

Make http.request work offline #17641

Closed
zvxayr opened this issue Dec 13, 2017 · 23 comments
Closed

Make http.request work offline #17641

zvxayr opened this issue Dec 13, 2017 · 23 comments

Comments

@zvxayr
Copy link

zvxayr commented Dec 13, 2017

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.

@zvxayr zvxayr changed the title Make http.get work offline Make http.request work offline Dec 13, 2017
@Trott
Copy link
Member

Trott commented Dec 13, 2017

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.

@Trott
Copy link
Member

Trott commented Dec 13, 2017

(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.)

@addaleax
Copy link
Member

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

@Trott
Copy link
Member

Trott commented Dec 13, 2017

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.

@addaleax
Copy link
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?

@gireeshpunathil
Copy link
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?

@zvxayr
Copy link
Author

zvxayr commented Dec 13, 2017

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.

@gireeshpunathil
Copy link
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)
#

@gireeshpunathil
Copy link
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.

@zvxayr
Copy link
Author

zvxayr commented Dec 13, 2017

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.

@gireeshpunathil
Copy link
Member

thanks. what does

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

output, with wifi off?

@zvxayr
Copy link
Author

zvxayr commented Dec 13, 2017

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

@gireeshpunathil
Copy link
Member

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

@gireeshpunathil
Copy link
Member

also ping @nodejs/collaborators for pointers.

@bnoordhuis
Copy link
Member

Can someone try this patch and see if it makes a difference?

diff --git a/deps/uv/src/win/getaddrinfo.c b/deps/uv/src/win/getaddrinfo.c
index 282d919cf7..aad7a96452 100644
--- a/deps/uv/src/win/getaddrinfo.c
+++ b/deps/uv/src/win/getaddrinfo.c
@@ -42,6 +42,7 @@ int uv__getaddrinfo_translate_error(int sys_err) {
     case WSAHOST_NOT_FOUND:       return UV_EAI_NONAME;
     case WSATYPE_NOT_FOUND:       return UV_EAI_SERVICE;
     case WSAESOCKTNOSUPPORT:      return UV_EAI_SOCKTYPE;
+    case WSANO_DATA:              return UV_EAI_NODATA;
     default:                      return uv_translate_sys_error(sys_err);
   }
 }

@gireeshpunathil
Copy link
Member

@bnoordhuis - thanks for this.
I need to see 2 things:

  • a system for building this
  • a recreate where I can test this.

@zvxayr - just checking, in case - are you in a position to build this patch?

@gibfahn
Copy link
Member

gibfahn commented Dec 13, 2017

@gireeshpunathil just push a branch to your fork that is master + @bnoordhuis 's patch, and then run node-test-commit against it.

@gireeshpunathil
Copy link
Member

@gibfahn - node-test-commit job does not provide a build with parameter option to me. Insufficient permissions?

@gireeshpunathil
Copy link
Member

https://ci.nodejs.org/job/node-test-commit/14798/console
managed to trigger one, but was a total failure. Can you please help?

@bzoz
Copy link
Contributor

bzoz commented Dec 13, 2017

Parameters needed some tweaking, CI: https://ci.nodejs.org/job/node-test-commit/14804/

@bzoz
Copy link
Contributor

bzoz commented Dec 13, 2017

With @bnoordhuis patch:

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

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

@bzoz
Copy link
Contributor

bzoz commented Dec 13, 2017

It can be simplified to:

require('dns').lookup('localhost', { hints: 1024 }, (err, addr, family) => {
    console.log(err);
})

This is how lookup is called in lib/net.js:1103. This extra hints option breaks this on Windows.

@bzoz
Copy link
Contributor

bzoz commented Dec 13, 2017

This is basically duplicate of #11320. That issue was closed because there was an easy userland fix.

IMHO we should remove dns.ADDRCONFIG in hints on Windows. See simillar issue in chromium https://bugs.chromium.org/p/chromium/issues/detail?id=5234

bzoz added a commit to JaneaSystems/node that referenced this issue Dec 13, 2017
On Windows setting ADDRCONFIG causes localhost resolution to fail if there are
no network connections. This removes that flag on Windows.

Fixes: nodejs#17641
@bzoz bzoz closed this as completed in a3497b3 Dec 21, 2017
MylesBorins pushed a commit that referenced this issue Jan 8, 2018
On Windows setting ADDRCONFIG causes localhost resolution to fail if there are
no network connections. This removes that flag on Windows.

Fixes: #17641
PR-URL: #17662
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
MylesBorins pushed a commit that referenced this issue Jan 9, 2018
On Windows setting ADDRCONFIG causes localhost resolution to fail if there are
no network connections. This removes that flag on Windows.

Fixes: #17641
PR-URL: #17662
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
MylesBorins pushed a commit that referenced this issue Jan 23, 2018
On Windows setting ADDRCONFIG causes localhost resolution to fail if there are
no network connections. This removes that flag on Windows.

Fixes: #17641
PR-URL: #17662
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
MylesBorins pushed a commit that referenced this issue Jan 23, 2018
On Windows setting ADDRCONFIG causes localhost resolution to fail if there are
no network connections. This removes that flag on Windows.

Fixes: #17641
PR-URL: #17662
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
gibfahn pushed a commit that referenced this issue Jan 24, 2018
On Windows setting ADDRCONFIG causes localhost resolution to fail if there are
no network connections. This removes that flag on Windows.

Fixes: #17641
PR-URL: #17662
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
MylesBorins pushed a commit that referenced this issue Feb 11, 2018
On Windows setting ADDRCONFIG causes localhost resolution to fail if there are
no network connections. This removes that flag on Windows.

Fixes: #17641
PR-URL: #17662
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
MylesBorins pushed a commit that referenced this issue Feb 12, 2018
On Windows setting ADDRCONFIG causes localhost resolution to fail if there are
no network connections. This removes that flag on Windows.

Fixes: #17641
PR-URL: #17662
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
MylesBorins pushed a commit that referenced this issue Feb 13, 2018
On Windows setting ADDRCONFIG causes localhost resolution to fail if there are
no network connections. This removes that flag on Windows.

Fixes: #17641
PR-URL: #17662
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
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

Successfully merging a pull request may close this issue.

7 participants