Fix deadlock when logger tries to use correlation #3426
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR fixes #3385 by preventing components initialization when calling the
Datadog::Tracing.correlation
API.Instead, we use the
allow_initialization: false
option, which was added exactly to help break these kinds of initialization cycles.Motivation:
This fixes a deadlock issue such as:
that happens when a logger is configured to also print correlation
Additional Notes:
While it may seem that I've changed the API semantics by returning an
Identifier
when there is no tracer, the previous code was actually misleading.There is actually no way (that I know of) for
tracer
to benil
on dd-trace-rb currently. It can be disabled, but an instance will still exist.The disabled instance, when called, returns an empty
Identifier
, so here I'm replicating that behavior, without needing the components to be initialized.I guess this is open for debate? We could return
nil
instead in the future.How to test the change?
This tiny snippet can be used to simulate the exact logger issue reported by the customer:
For Datadog employees:
credentials of any kind, I've requested a review from
@DataDog/security-design-and-guidance
.Fixes #3385