Skip to content

wip: introduce safe callbacks and use in rewriting init manager#6245

Closed
mergeconflict wants to merge 2 commits intoenvoyproxy:masterfrom
mergeconflict:callback
Closed

wip: introduce safe callbacks and use in rewriting init manager#6245
mergeconflict wants to merge 2 commits intoenvoyproxy:masterfrom
mergeconflict:callback

Conversation

@mergeconflict
Copy link
Copy Markdown

Introduce a new, "safe" callback mechanism (as in, it's safe to invoke the callback after the receiver has been destroyed), and use it as the basis for a new init manager. See #6116 and #6136 for background.

This is work in progress; I haven't updated use sites yet. Seeking feedback on the basic design.

Signed-off-by: Dan Rosen mergeconflict@google.com

Signed-off-by: Dan Rosen <mergeconflict@google.com>
@htuch htuch self-requested a review March 11, 2019 15:31
@htuch htuch self-assigned this Mar 11, 2019
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

I like the fact that we're now moving to a safer-by-default model here. Some questions on the new model..

* Explicit conversion to bool, to test whether the receiver contains a callback function.
* @return true if the corresponding Receiver contains a callback, false otherwise.
*/
explicit operator bool() const { return static_cast<bool>(fn_); }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: prefer fn_ != nullptr.

@@ -0,0 +1,80 @@
#include "init/callback.h"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should probably be source/common/init, this isn't a top-level Envoy concern.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I was wondering about that. The current state of master is sort of weird:

  • The Init::Manager and Init::Target interfaces are defined in include/envoy/init
  • The InitManagerImpl class is defined in source/server with a TODO comment, "Move InitManagerImpl into a new subdirectory in source/ called init/"

I agree it'd make sense to move the implementation into source/common/init. What would you think about also moving the interfaces down into include/envoy/common/init?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

source/common/init for implementation, include/envoy/init for interface; that's how Envoy canonical paths work.

* Caller and Receiver are simple wrappers for their counterparts in Common::Callback with logging
* added to help debug initialization and destruction ordering issues that occasionally arise.
*/
class Caller : Logger::Loggable<Logger::Id::init> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wait, why is there a Caller/Receiver defined here as well as earlier on? :) Can't we just have one abstract version of this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The Caller/Receiver in common/callback are meant to be as bare-bones as possible, with no logging included. Going on the assumption that we want safer callbacks everywhere, not just in initialization, I didn't want to bake logging as a requirement.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We definitely want to converge these implementations IMHO; even if we have to use macro magic or somethign to do it. They are pretty complicated to reason about, having only a single one is the way to go.

Signed-off-by: Dan Rosen <mergeconflict@google.com>
htuch pushed a commit that referenced this pull request Mar 22, 2019
Introduce a new "safe" init manager, to replace the existing one that's prone to use-after-free issues (see e.g. #6116). Users of the existing init manager will be upgraded one-by-one in subsequent PRs if this design is approved. See also previous false starts in PRs #6136 and #6245.

Risk Level: Low, no existing users of the existing init manager are changed in this PR.
Testing: New unit tests added.
Docs Changes: n/a
Release Notes: n/a

Signed-off-by: Dan Rosen <mergeconflict@google.com>
@mergeconflict mergeconflict deleted the callback branch March 27, 2019 14:02
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.

2 participants