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

dns: make library_inited_ state global #14738

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class ChannelWrap : public AsyncWrap {
inline uv_timer_t* timer_handle() { return timer_handle_; }
inline ares_channel cares_channel() { return channel_; }
inline bool query_last_ok() const { return query_last_ok_; }
static inline bool library_inited() { return library_inited_; }
inline void set_query_last_ok(bool ok) { query_last_ok_ = ok; }
inline bool is_servers_default() const { return is_servers_default_; }
inline void set_is_servers_default(bool is_default) {
Expand All @@ -157,18 +158,19 @@ class ChannelWrap : public AsyncWrap {
ares_channel channel_;
bool query_last_ok_;
bool is_servers_default_;
bool library_inited_;
static bool library_inited_;
node_ares_task_list task_list_;
};

bool ChannelWrap::library_inited_ = false;

ChannelWrap::ChannelWrap(Environment* env,
Local<Object> object)
: AsyncWrap(env, object, PROVIDER_DNSCHANNEL),
timer_handle_(nullptr),
channel_(nullptr),
query_last_ok_(true),
is_servers_default_(true),
library_inited_(false) {
is_servers_default_(true) {
RB_INIT(&task_list_);

MakeWeak<ChannelWrap>(this);
Expand Down Expand Up @@ -493,19 +495,17 @@ void ChannelWrap::Setup() {
if (r != ARES_SUCCESS)
return env()->ThrowError(ToErrorCodeString(r));
}
library_inited_ = true;

/* We do the call to ares_init_option for caller. */
r = ares_init_options(&channel_,
&options,
ARES_OPT_FLAGS | ARES_OPT_SOCK_STATE_CB);

if (r != ARES_SUCCESS) {
ares_library_cleanup();
return env()->ThrowError(ToErrorCodeString(r));
}

library_inited_ = true;

/* Initialize the timeout timer. The timer won't be started until the */
/* first socket is opened. */
CleanupTimer();
Expand All @@ -516,9 +516,6 @@ void ChannelWrap::Setup() {


ChannelWrap::~ChannelWrap() {
if (library_inited_)
ares_library_cleanup();

ares_destroy(channel_);
CleanupTimer();
}
Expand Down