Skip to content

server: fix server lifecycle notifier when callback list is empty#7103

Merged
mattklein123 merged 1 commit intoenvoyproxy:masterfrom
eziskind:debug
Jun 3, 2019
Merged

server: fix server lifecycle notifier when callback list is empty#7103
mattklein123 merged 1 commit intoenvoyproxy:masterfrom
eziskind:debug

Conversation

@eziskind
Copy link
Contributor

Description: Now that lifecycle notification registrations can be canceled (with #6984) the list of registered callbacks could be empty, so need to remove an ASSERT. Also simplified the code to defer execution of the completion_cb until all registered callbacks have been notified - copied the approach used in #7011 which wraps the completion callback in a shared_ptr. This allows removing the special-case code where there are no registered callbacks.
Risk Level: low
Testing: unit tests

Signed-off-by: Elisha Ziskind eziskind@google.com

Signed-off-by: Elisha Ziskind <eziskind@google.com>
@jmarantz jmarantz self-assigned this May 31, 2019
Copy link
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

LGTM basically, but 2 nits:

  • can we use thread-factory rather than going directly to std::thread
  • I assume the old impl would fail with the new test. How would it fail? The assert on line old 619?

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)(); });
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL: the () in lambdas is optional.

// 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_);
Copy link
Contributor

Choose a reason for hiding this comment

The 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..

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

// 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) {
Copy link
Contributor

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.

@eziskind
Copy link
Contributor Author

  • can we use thread-factory rather than going directly to std::thread

As mentioned, I was just copying the pattern used in TLS. Do you want me to switch to use the thread factory in this PR?

  • I assume the old impl would fail with the new test. How would it fail? The assert on line old 619?

Yes - the old assert would fail with the new test.

@jmarantz
Copy link
Contributor

No, let's not grow the PR especially as there were already-existing uses. Those will all have to be cleaned up, I presume, at some point for portability.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Nice!

@mattklein123 mattklein123 merged commit cd9e7ae into envoyproxy:master Jun 3, 2019
@eziskind eziskind deleted the debug branch June 3, 2019 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants