-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Comments
|
(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.) |
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 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. |
Mh, the part that I’m not sure about: Can a string like |
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
that is different from what was reported. So probably root cause is something else? |
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. |
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.
|
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. |
by the way, I am running a node server that listens on port 8000. entering |
thanks. what does require('dns').lookup('localhost', (e, a) => {console.log(a)}) output, with wifi off? |
thanks. 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 |
thanks for the info. let me investigate further with exact windows and node versions |
also ping @nodejs/collaborators for pointers. |
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);
}
} |
@bnoordhuis - thanks for this.
@zvxayr - just checking, in case - are you in a position to build this patch? |
@gireeshpunathil just push a branch to your fork that is master + @bnoordhuis 's patch, and then run |
@gibfahn - |
https://ci.nodejs.org/job/node-test-commit/14798/console |
Parameters needed some tweaking, CI: https://ci.nodejs.org/job/node-test-commit/14804/ |
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) |
It can be simplified to: require('dns').lookup('localhost', { hints: 1024 }, (err, addr, family) => {
console.log(err);
}) This is how |
This is basically duplicate of #11320. That issue was closed because there was an easy userland fix. IMHO we should remove |
On Windows setting ADDRCONFIG causes localhost resolution to fail if there are no network connections. This removes that flag on Windows. Fixes: nodejs#17641
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>
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>
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>
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>
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>
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>
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>
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>
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:
I ran the client code online and it works so I suspect that
http.request
does not work without internet connectivity.The text was updated successfully, but these errors were encountered: