Skip to content

context: log severe warning if ancestry chain > 1000 - #3459

Merged
zpencer merged 3 commits into
grpc:masterfrom
zpencer:context-ancestor-depth-validation
Sep 14, 2017
Merged

zpencer merged 3 commits into
grpc:masterfrom
zpencer:context-ancestor-depth-validation

Conversation

@zpencer

@zpencer zpencer commented Sep 14, 2017

Copy link
Copy Markdown
Contributor

If a context has an unreasonable number of ancestors, then
chances are this is an application error. Log the stack trace to
notify the user and aid in debugging.

@zpencer
zpencer requested a review from ejona86 September 14, 2017 03:01

@codefromthecrypt codefromthecrypt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

seems ok though sometimes people do create tons of trace spans (which relate to context forks). Also not sure the combinatory effect (ex scoping metrics then later scoping deadlin, tracing etc). This sort of practice would get to a good default number which 200 likely is

cc @bogdandrutu

@codefromthecrypt

Copy link
Copy Markdown

would be nice to show the max ancestry in a "typical" grpc app, configured with metrics and tracing, just for comparison's sake

// The threshold and interval are arbitrarily chosen.
// VisibleForTesting
static final int CONTEXT_DEPTH_WARN_THRESH = 200;
private static final int CONTEXT_WARN_INTERVAL = 20;

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.

Let's not do the interval warning at this point. Since we've not been warning before, let's start slow.

// Long chains of contexts are suspicious and usually indicate a misuse of Context.
// The threshold and interval are arbitrarily chosen.
// VisibleForTesting
static final int CONTEXT_DEPTH_WARN_THRESH = 200;

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.

@adriancole, I'm okay with bumping this higher. If you're concerned about 200, do you have a suggestion on where to start, like 1000 or 5000?

The main concern at the moment is infinite mutation, because finding those in real life applications can be hard.

@codefromthecrypt

codefromthecrypt commented Sep 14, 2017 via email

Copy link
Copy Markdown

@zpencer zpencer changed the title context: log severe warning if ancestry chain > 200 context: log severe warning if ancestry chain > 1000 Sep 14, 2017
@zpencer
zpencer merged commit 86dec11 into grpc:master Sep 14, 2017
@zpencer
zpencer deleted the context-ancestor-depth-validation branch November 7, 2017 18:30
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants