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

tracing_subscriber::Registry misbehaves when exiting span while some other subscriber is default #1656

Open
lilyball opened this issue Oct 20, 2021 · 3 comments

Comments

@lilyball
Copy link
Contributor

Bug Report

Version

asdf-tracing v0.1.0 (/Users/lily/Dev/Scratch/asdf-tracing)
├── tracing v0.1.29
│   ├── tracing-attributes v0.1.18 (proc-macro)
│   └── tracing-core v0.1.21
└── tracing-subscriber v0.2.25
    ├── tracing v0.1.29 (*)
    ├── tracing-core v0.1.21 (*)
    ├── tracing-log v0.1.2
    │   └── tracing-core v0.1.21 (*)
    └── tracing-serde v0.1.2
        └── tracing-core v0.1.21 (*)

Platform

Darwin DeerBook 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64

Crates

tracing-subscriber

Description

If I exit a span created from something using Registry (such as FmtSubscriber) while its associated dispatch is not the default dispatch, Registry will ask the default dispatch to try_close() the span id. This means it's asking the wrong dispatch to close it, which can lead to panics.

Reproduction

let outer = tracing_subscriber::fmt().set_default();
let one = info_span!("one").entered();
let inner = tracing_subscriber::fmt().set_default();
let two = info_span!("two").entered();
drop(one); // this closes span two
drop(two); // this panics
thread 'main' panicked at 'tried to drop a ref to Id(1), but no such span exists!', /Users/lily/.cargo/registry/src/github.com-1ecc6299db9ec823/tracing-subscriber-0.2.25/src/registry/sharded.rs:346:21
@hawkw
Copy link
Member

hawkw commented Oct 20, 2021

The neatest solution to this is probably just to change the Registry type to not need to get the current default dispatch in try_close...which I started experimenting with in #1505. Unfortunately, this requires some API changes, and introduces a few new issues I haven't quite had the time to work out.

Another option is to change the Span type to set its Dispatch as the default for the duration of the try_close call, but this seems like an unfortunate perf hit...

@lilyball
Copy link
Contributor Author

Setting Dispatch as the default also will hit #1655 if we're in a get_default() closure.

@juchiast
Copy link

Is there any update on this?

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

No branches or pull requests

3 participants