Skip to content

Commit a68b75d

Browse files
author
smorivan
committed
bug core: fix http client destruction order
This fixes crashes on service shutdown after the "split `HttpClientCore` and `HttpClient`" PR. Estimated crash root cause: `components::TestsuiteSupport` could (via `testsuite::HttpAllowedUrlsExtra`) hold onto `clients::http::ClientCore` past the destruction of `components::HttpClientCore`. This would lead to `clients::http::ClientCore` continuing to serve detached requests (via `easy` & `multi`) after the dependencies of `HttpClientCore` (including `clients::dns::Component`, `components::StatisticsStorage`, `components::DynamicConfig`, and a part of `components::TestsuiteSupport` fields) are destroyed, which caused use-after-free in HTTP client internals. commit_hash:8fd7fa69bc78c0cce74aa0fc6194f6169e703ffe
1 parent 6529f5c commit a68b75d

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

core/include/userver/testsuite/http_allowed_urls_extra.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ namespace testsuite {
1616

1717
class HttpAllowedUrlsExtra final {
1818
public:
19-
void RegisterHttpClient(std::shared_ptr<clients::http::ClientCore> http_client);
19+
void RegisterHttpClient(clients::http::ClientCore& http_client);
2020

2121
void SetAllowedUrlsExtra(std::vector<std::string>&& urls);
2222

2323
private:
24-
std::shared_ptr<clients::http::ClientCore> http_client_{nullptr};
24+
clients::http::ClientCore* http_client_{nullptr};
2525
};
2626

2727
} // namespace testsuite

core/src/clients/http/component_core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ HttpClientCore::HttpClientCore(const ComponentConfig& component_config, const Co
9393
http_client_->SetTestsuiteConfig({prefixes, timeout});
9494

9595
auto& testsuite = context.FindComponent<components::TestsuiteSupport>();
96-
testsuite.GetHttpAllowedUrlsExtra().RegisterHttpClient(http_client_);
96+
testsuite.GetHttpAllowedUrlsExtra().RegisterHttpClient(*http_client_);
9797
}
9898

9999
clients::http::impl::Config bootstrap_config;

core/src/testsuite/http_allowed_urls_extra.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ USERVER_NAMESPACE_BEGIN
88

99
namespace testsuite {
1010

11-
void HttpAllowedUrlsExtra::RegisterHttpClient(std::shared_ptr<clients::http::ClientCore> http_client) {
12-
http_client_ = std::move(http_client);
13-
}
11+
void HttpAllowedUrlsExtra::RegisterHttpClient(clients::http::ClientCore& http_client) { http_client_ = &http_client; }
1412

1513
void HttpAllowedUrlsExtra::SetAllowedUrlsExtra(std::vector<std::string>&& urls) {
1614
if (http_client_) {

0 commit comments

Comments
 (0)