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: Entered guards should be !Send #698

Closed
hawkw opened this issue Apr 28, 2020 · 0 comments · Fixed by #1001
Closed

tracing: Entered guards should be !Send #698

hawkw opened this issue Apr 28, 2020 · 0 comments · Fixed by #1001
Labels
crate/tracing Related to the `tracing` crate kind/bug Something isn't working meta/breaking This is a breaking change, and should wait until the next breaking release.
Milestone

Comments

@hawkw
Copy link
Member

hawkw commented Apr 28, 2020

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...

@hawkw hawkw added kind/bug Something isn't working crate/tracing Related to the `tracing` crate meta/breaking This is a breaking change, and should wait until the next breaking release. labels Apr 28, 2020
@hawkw hawkw added this to the tracing 0.2 milestone Apr 28, 2020
hawkw added a commit that referenced this issue Sep 29, 2020
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.

This PR adds a `*mut ()` field to `Entered` so that it no longer
implements `Send`. There's now a manual `Sync` impl so structs holding
an `Entered` can still be `Sync`.

Fixes #698

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this issue Sep 30, 2020
## Motivation

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.

## Solution

This PR adds a `*mut ()` field to `Entered` so that it no longer
implements `Send`. There's now a manual `Sync` impl so structs holding
an `Entered` can still be `Sync`.

Fixes #698

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/tracing Related to the `tracing` crate kind/bug Something isn't working meta/breaking This is a breaking change, and should wait until the next breaking release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant