Skip to content
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

Prevent infinite loop when using reserved fields #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

abusch
Copy link

@abusch abusch commented Jul 16, 2023

Attempt at fixing #33 by explicitly setting parent: None when calling tracing::debug!() in BunyanFormattingLayer. Also check whether the event is a "root" event before resolving the "current context" in on_event().

Testing this was tricky, as it turns out the infinite loop only happens if the subscriber is installed globally (i.e with tracing::subscriber::set_global_default()). When using a thread-local subscriber, such as with tracing::subscriber::with_default(), tracing prevents you from re-entrantly acquiring the subscriber, returning a dummy NONE subscriber the second time (which means the logs from BunyanFormattingLayer are always lost in that case). See https://github.com/tokio-rs/tracing/blob/v0.1.x/tracing-core/src/dispatcher.rs#L384

closes: #33

Comment on lines 319 to 331
let current_span = if event.is_root() {
None
} else {
// Events do not necessarily happen in the context of a span, hence lookup_current
// returns an `Option<SpanRef<_>>` instead of a `SpanRef<_>`.
ctx.lookup_current()
};
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure this is correct.
I think we should:

Copy link
Author

Choose a reason for hiding this comment

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

Right, I think that makes sense.

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.

Infinite loop in some circumstances
2 participants