Skip to content

tracing: Entered guards should be !Send #698

Closed
@hawkw

Description

@hawkw

Bug Report

Version

  • all

Crates

  • tracing

Description

The Entered guard returned by Span::enter represents entering and exiting a span on the current thread. Calling Span::enter enters the span, returning an Entered, and dropping the Entered ensures that the span is exited. This ensures that all spans, once entered, are eventually exited.

However, Entered has an auto-impl of Send, because it doesn't contain any !Send types. This means that the Entered guard could be sent to another thread and dropped. This would cause the original thread to never exit the span,. and the thread to which the Entered guard was sent would exit a span that it never observed an enter for. This is incorrect.

We should consider making Entered !Send. Technically, this is a breaking change, but the current behavior is incorrect. This would also prevent Entered guards from being held in futures that are bounded with Send, which would prevent some incorrect uses of Span::enter in async blocks...

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/tracingRelated to the `tracing` cratekind/bugSomething isn't workingmeta/breakingThis is a breaking change, and should wait until the next breaking release.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions