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

backport to 1.16: aggregate cluster: fix TLS init issue #14456

Merged
merged 3 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Bug Fixes
---------
*Changes expected to improve the state of the world and are unlikely to have negative effects*

* aggregate cluster: fixed a crash due to a TLS initialization issue.

Removed Config or Runtime
-------------------------
*Normally occurs at the end of the* :ref:`deprecation period <deprecated>`
Expand Down
4 changes: 3 additions & 1 deletion source/extensions/clusters/aggregate/cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Cluster::Cluster(const envoy::config::cluster::v3::Cluster& cluster,
: Upstream::ClusterImplBase(cluster, runtime, factory_context, std::move(stats_scope),
added_via_api),
cluster_manager_(cluster_manager), runtime_(runtime), random_(random),
tls_(tls.allocateSlot()), clusters_(config.clusters().begin(), config.clusters().end()) {}
tls_(tls.allocateSlot()), clusters_(config.clusters().begin(), config.clusters().end()) {
tls_->set([](Event::Dispatcher&) { return nullptr; });
}

PriorityContextPtr
Cluster::linearizePrioritySet(const std::function<bool(const std::string&)>& skip_predicate) {
Expand Down
9 changes: 8 additions & 1 deletion test/mocks/thread_local/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,23 @@ class MockInstance : public Instance {
}

// ThreadLocal::Slot
ThreadLocalObjectSharedPtr get() override { return parent_.data_[index_]; }
ThreadLocalObjectSharedPtr get() override {
EXPECT_TRUE(was_set_);
return parent_.data_[index_];
}
bool currentThreadRegistered() override { return parent_.registered_; }
void runOnAllThreads(const UpdateCb& cb) override {
EXPECT_TRUE(was_set_);
parent_.runOnAllThreads([cb, this]() { parent_.data_[index_] = cb(parent_.data_[index_]); });
}
void runOnAllThreads(const UpdateCb& cb, Event::PostCb main_callback) override {
EXPECT_TRUE(was_set_);
parent_.runOnAllThreads([cb, this]() { parent_.data_[index_] = cb(parent_.data_[index_]); },
main_callback);
}

void set(InitializeCb cb) override {
was_set_ = true;
if (parent_.defer_data) {
parent_.deferred_data_[index_] = cb;
} else {
Expand All @@ -78,6 +84,7 @@ class MockInstance : public Instance {

MockInstance& parent_;
const uint32_t index_;
bool was_set_{}; // set() must be called before other functions.
};

void call() {
Expand Down