dns: fix `resolve` failed starts without network · nodejs/node@6518932 · GitHub
Skip to content

Commit 6518932

Browse files
XadillaXMylesBorins
authored andcommitted
dns: fix resolve failed starts without network
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>
1 parent a1cef1f commit 6518932

3 files changed

Lines changed: 110 additions & 74 deletions

File tree

src/cares_wrap.cc

Lines changed: 86 additions & 74 deletions

src/env-inl.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ inline Environment::Environment(v8::Local<v8::Context> context,
219219
: isolate_(context->GetIsolate()),
220220
isolate_data_(IsolateData::GetOrCreate(context->GetIsolate(), loop)),
221221
timer_base_(uv_now(loop)),
222+
cares_query_last_ok_(true),
223+
cares_is_servers_default_(true),
222224
using_domains_(false),
223225
printed_error_(false),
224226
trace_sync_io_(false),
@@ -453,6 +455,22 @@ inline ares_channel* Environment::cares_channel_ptr() {
453455
return &cares_channel_;
454456
}
455457

458+
inline bool Environment::cares_query_last_ok() {
459+
return cares_query_last_ok_;
460+
}
461+
462+
inline void Environment::set_cares_query_last_ok(bool ok) {
463+
cares_query_last_ok_ = ok;
464+
}
465+
466+
inline bool Environment::cares_is_servers_default() {
467+
return cares_is_servers_default_;
468+
}
469+
470+
inline void Environment::set_cares_is_servers_default(bool is_default) {
471+
cares_is_servers_default_ = is_default;
472+
}
473+
456474
inline node_ares_task_list* Environment::cares_task_list() {
457475
return &cares_task_list_;
458476
}

src/env.h

Lines changed: 6 additions & 0 deletions

0 commit comments

Comments
 (0)