-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
dns: fix resolve
failed starts without network
#13076
dns: fix resolve
failed starts without network
#13076
Conversation
8662937
to
57f04fd
Compare
Anyone who has time to review this code? |
src/env-inl.h
Outdated
|
||
inline void Environment::cares_servers_use_default(bool is_default) { | ||
cares_is_servers_use_default_ = is_default; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance you could name the setters set_FLAG()
and the getters just FLAG()
(compare with e.g. using_domains
)?
src/cares_wrap.cc
Outdated
@@ -1306,6 +1373,8 @@ void SetServers(const FunctionCallbackInfo<Value>& args) { | |||
|
|||
delete[] servers; | |||
|
|||
if (err == ARES_SUCCESS) env->cares_servers_use_default(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extremely tiny nit: I’d put these on separate lines
src/cares_wrap.cc
Outdated
@@ -328,10 +386,18 @@ class QueryWrap : public AsyncWrap { | |||
return static_cast<void*>(this); | |||
} | |||
|
|||
static void AresQuery(Environment* env, const char* name, | |||
int dnsclass, int type, ares_callback callback, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize the code around this doesn’t do it either, but once more, would you mind aligning the arguments vertically? 😄
src/cares_wrap.cc
Outdated
* The fallback servers of cares is [ "127.0.0.1" ] with no user additional | ||
* setting. | ||
*/ | ||
void AresCheckServers(Environment* env) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit: Check
sounds a bit like it’s just testing things, maybe Ensure
is better?
src/cares_wrap.cc
Outdated
/* We do the call to ares_init_option for caller. */ | ||
int r = ares_init_options(env->cares_channel_ptr(), | ||
&options, | ||
ARES_OPT_FLAGS | ARES_OPT_SOCK_STATE_CB); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(ditto for aligning)
memset(&options, 0, sizeof(options)); | ||
options.flags = ARES_FLAG_NOCHECKRESP; | ||
options.sock_state_cb = ares_sockstate_cb; | ||
options.sock_state_cb_data = env; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we somehow share this code with Initialize
, to make it more obviously correct? It looks like there’s quite a bit that could be shared
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'v extracted these code to SetupCaresChannel()
.
57f04fd
to
51caf53
Compare
One of Windows CI Machines failed. I wonder why.
|
I don't know why, maybe it's the bug of CI? I'm not sure. @addaleax |
Yes, the CI failure is nothing to worry about. 👍 (It’s not a bug in the CI but it’s a known failure that’s not related to this PR.) |
51caf53
to
490672c
Compare
Hey @addaleax I've already rebased for some conflicts with |
CI is green. Maybe @bnoordhuis or @silverwind could give this a look, too? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo comments.
src/cares_wrap.cc
Outdated
ns_c_in, | ||
ns_t_a, | ||
Callback, | ||
GetQueryArg()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fits on one line now.
src/cares_wrap.cc
Outdated
ns_c_in, | ||
ns_t_aaaa, | ||
Callback, | ||
GetQueryArg()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise. I'll stop pointing it out from here on.
@XadillaX Actually, one more thing: your author name in this commit is given as “XadillaX”. Is that intended or do you prefer to be listed (changelog, git log, AUTHORS file) with some other name? People typically prefer their full name, but ultimately it’s up to you. (Edit: Just to be clear, that name doesn’t have to be ASCII-only – whatever you prefer, really.) |
Fix the bug that you start process without network at first, but it connected lately, `dns.resolve` will stay failed with ECONNREFUSED because c-ares servers fallback to 127.0.0.1 at the very beginning. If c-ares servers "127.0.0.1" is detected and its not set by user self, and last query is not OK, recreating `ares_channel` operation will be triggered to reload servers. Fixes: nodejs#1644
490672c
to
355a33b
Compare
@addaleax I think 'XadillaX - Khaidi Chu' would be fine to me. |
@addaleax I mean I'd like to use XadillaX when in git log, changelog and authors file. And if someday I have the honor of being a collaborator, I'd like to use 'XadillaX - Khaidi Chu' in the list. |
Fix the bug that you start process without network at first, but it connected lately, `dns.resolve` will stay failed with ECONNREFUSED because c-ares servers fallback to 127.0.0.1 at the very beginning. If c-ares servers "127.0.0.1" is detected and its not set by user self, and last query is not OK, recreating `ares_channel` operation will be triggered to reload servers. Fixes: #1644 PR-URL: #13076 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@addaleax Thanks. I wondered if this PR passed the coverity? Shall I trigger that by myself? |
@XadillaX I am not sure how to do that. I think the tool gets run periodically without being triggered, but really, I’m not sure. |
see #13117 (comment) |
Should this be backported to v6.x? If so it will require to be done manually |
Fix the bug that you start process without network at first, but it connected lately, `dns.resolve` will stay failed with ECONNREFUSED because c-ares servers fallback to 127.0.0.1 at the very beginning. If c-ares servers "127.0.0.1" is detected and its not set by user self, and last query is not OK, recreating `ares_channel` operation will be triggered to reload servers. Fixes: nodejs#1644 PR-URL: nodejs#13076 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
|
Fix the bug that you start process without network at first, but it connected lately, `dns.resolve` will stay failed with ECONNREFUSED because c-ares servers fallback to 127.0.0.1 at the very beginning. If c-ares servers "127.0.0.1" is detected and its not set by user self, and last query is not OK, recreating `ares_channel` operation will be triggered to reload servers. Fixes: #1644 Backport-PR-URL: #14434 PR-URL: #13076 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Fix the bug that you start process without network at first, but it connected lately, `dns.resolve` will stay failed with ECONNREFUSED because c-ares servers fallback to 127.0.0.1 at the very beginning. If c-ares servers "127.0.0.1" is detected and its not set by user self, and last query is not OK, recreating `ares_channel` operation will be triggered to reload servers. Fixes: #1644 Backport-PR-URL: #14434 PR-URL: #13076 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Fix the bug that you start process without network at first, but it connected lately, `dns.resolve` will stay failed with ECONNREFUSED because c-ares servers fallback to 127.0.0.1 at the very beginning. If c-ares servers "127.0.0.1" is detected and its not set by user self, and last query is not OK, recreating `ares_channel` operation will be triggered to reload servers. Fixes: #1644 Backport-PR-URL: #14434 PR-URL: #13076 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Fix the bug that you start process without network at first, but it connected lately,
dns.resolve
will stay failed with ECONNREFUSED because c-ares servers fallback to 127.0.0.1 at the very beginning.If c-ares servers "127.0.0.1" is detected and its not set by user self, and last query is not OK, recreating
ares_channel
operation will be triggered to reload servers.You can test with this script:
Turn off your network at first before starting this script. Then try to open the network and then turn off. Make the steps above in a loop and you will get the result.
Fixes: #1644
Solutaion
DNS server matches follow conditions is considered as a fallback server of c-ares:
[ "127.0.0.1" ]
; (the fallback server is exactly this value)dns.setServers
.I created two flags at the process start up.
cares_query_last_ok_
indicates that is last dns query succeeded or not;cares_is_servers_use_default_
indicates that whether current dns servers is the fallback 127.0.0.1 that c-ares initialized at the beginning.If
cares_query_last_ok_
istrue
orcares_is_servers_use_default_
isfalse
, everything will be OK.If not, the code will check current dns servers to see if it's 127.0.0.1 (maybe c-ares' fallback server). When it's 127.0.0.1, old
ares_channel
will be released and a new one will be created.Once one query succeeded or not ECONNREFUSED,
cares_query_last_ok_
will be marked astrue
. And once user set dns servers viadns.setServers
,cares_is_servers_use_default_
will be marked asfalse
. And what's more, once the first check found the dns servers is not 127.0.0.1,cares_is_servers_use_default_
also will be marked asfalse
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
dns