-
Notifications
You must be signed in to change notification settings - Fork 5.3k
server: fix server lifecycle notifier when callback list is empty #7103
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
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 |
|---|---|---|
|
|
@@ -614,23 +614,21 @@ void InstanceImpl::notifyCallbacksForStage(Stage stage, Event::PostCb completion | |
| } | ||
| } | ||
|
|
||
| // Wrap completion_cb so that it only gets invoked when all callbacks for this stage | ||
| // have finished their work. | ||
| std::shared_ptr<Event::PostCb> cb_guard(new Event::PostCb([] {}), | ||
| [this, completion_cb](Event::PostCb* cb) { | ||
| ASSERT(std::this_thread::get_id() == main_thread_id_); | ||
|
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. I hadn't seen the original PR, but why are we not using the thread-factory abstraction here? We have easy access to it via server_->api..
Contributor
Author
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. No special reason - I think I just copied a similar pattern used in TLS |
||
| completion_cb(); | ||
| delete cb; | ||
| }); | ||
|
|
||
| auto it2 = stage_completable_callbacks_.find(stage); | ||
| if (it2 != stage_completable_callbacks_.end()) { | ||
| ASSERT(!it2->second.empty()); | ||
| // Wrap completion_cb so that it only gets invoked when all callbacks for this stage | ||
| // have finished their work. | ||
| auto completion_cb_count = std::make_shared<int>(it2->second.size()); | ||
| Event::PostCb wrapped_cb = [this, completion_cb, completion_cb_count] { | ||
| ASSERT(std::this_thread::get_id() == main_thread_id_); | ||
| if (--*completion_cb_count == 0) { | ||
| completion_cb(); | ||
| } | ||
| }; | ||
| ENVOY_LOG(info, "Notifying {} callback(s) with completion.", it2->second.size()); | ||
| for (const StageCallbackWithCompletion& callback : it2->second) { | ||
| callback(wrapped_cb); | ||
| callback([cb_guard] { (*cb_guard)(); }); | ||
|
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. TIL: the |
||
| } | ||
| } else { | ||
| completion_cb(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL: you can specify a deleter with a shared-pointer. Very cool.