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

stats: fix merge during shutdown #3289

Merged
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion source/common/stats/thread_local_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void ThreadLocalStoreImpl::shutdownThreading() {
}

void ThreadLocalStoreImpl::mergeHistograms(PostMergeCb merge_complete_cb) {
ASSERT(!merge_in_progress_);
if (!shutting_down_) {
ASSERT(!merge_in_progress_);
merge_in_progress_ = true;
tls_->runOnAllThreads(
[this]() -> void {
Expand All @@ -109,6 +109,9 @@ void ThreadLocalStoreImpl::mergeHistograms(PostMergeCb merge_complete_cb) {
}
},
[this, merge_complete_cb]() -> void { mergeInternal(merge_complete_cb); });
} else {
// If server is shutting down, just call the callback to allow flush to continue.
merge_complete_cb();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for this case.

}
}

Expand Down
23 changes: 23 additions & 0 deletions test/common/stats/thread_local_store_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,29 @@ TEST_F(StatsThreadLocalStoreTest, ShuttingDown) {
EXPECT_CALL(*this, free(_)).Times(5);
}

TEST_F(StatsThreadLocalStoreTest, MergeDuringShutDown) {
InSequence s;
store_->initializeThreading(main_thread_dispatcher_, tls_);

Histogram& h1 = store_->histogram("h1");
EXPECT_EQ("h1", h1.name());

EXPECT_CALL(sink_, onHistogramComplete(Ref(h1), 1));
h1.recordValue(1);

store_->shutdownThreading();

// Validate that merge callback is called during shutdown and there is no ASSERT.
bool merge_called = false;
store_->mergeHistograms([&merge_called]() -> void { merge_called = true; });

EXPECT_TRUE(merge_called);

tls_.shutdownThread();

EXPECT_CALL(*this, free(_));
}

// Histogram tests
TEST_F(HistogramTest, BasicSingleHistogramMerge) {
Histogram& h1 = store_->histogram("h1");
Expand Down