-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Only call ares_library_init()/cleanup() routines in process_wide() if ares extension used in DNS resolving. #21884
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
Changes from all commits
d20706b
f9751b7
c4aaa4b
95d2216
d425d91
d22cb61
f37c515
838aa9c
e4576ac
8a3d24e
ca388d0
09f15d7
6a26ee9
76faa30
8f2cb43
10a71ed
629e580
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -493,7 +493,8 @@ DnsResolverImpl::AddrInfoPendingResolution::availableInterfaces() { | |
| } | ||
|
|
||
| // c-ares DNS resolver factory | ||
| class CaresDnsResolverFactory : public DnsResolverFactory { | ||
| class CaresDnsResolverFactory : public DnsResolverFactory, | ||
| public Logger::Loggable<Logger::Id::dns> { | ||
| public: | ||
| std::string name() const override { return std::string(CaresDnsResolver); } | ||
|
|
||
|
|
@@ -521,6 +522,29 @@ class CaresDnsResolverFactory : public DnsResolverFactory { | |
| } | ||
| return std::make_shared<Network::DnsResolverImpl>(cares, dispatcher, resolvers); | ||
| } | ||
|
|
||
| void initialize() override { | ||
| // Initialize c-ares library in case first time. | ||
| absl::MutexLock lock(&mutex_); | ||
| if (!ares_library_initialized_) { | ||
| ares_library_initialized_ = true; | ||
| ENVOY_LOG(info, "c-ares library initialized."); | ||
| ares_library_init(ARES_LIB_INIT_ALL); | ||
| } | ||
| } | ||
| void terminate() override { | ||
| // Cleanup c-ares library if initialized. | ||
| absl::MutexLock lock(&mutex_); | ||
| if (ares_library_initialized_) { | ||
| ares_library_initialized_ = false; | ||
| ENVOY_LOG(info, "c-ares library cleaned up."); | ||
| ares_library_cleanup(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move this cleanup to the ares factory destructor? That would feel a little cleaner.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't do it in the destructor since factories are statically initialized and will race with whatever static clean-up happens in c-ares.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Can you comment that the destructor is not called in deterministic order as the object is statically constructed. |
||
| } | ||
| } | ||
|
|
||
| private: | ||
| bool ares_library_initialized_ ABSL_GUARDED_BY(mutex_){false}; | ||
| absl::Mutex mutex_; | ||
| }; | ||
|
|
||
| // Register the CaresDnsResolverFactory | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.