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

sentry-tower: using the layer breaks with axum ~0.8 because it's not Sync #720

Open
syphar opened this issue Jan 3, 2025 · 0 comments
Open

Comments

@syphar
Copy link

syphar commented Jan 3, 2025

Environment

  • sentry 0.35.0
  • axum 0.8.1

Steps to Reproduce

When upgrading docs.rs itself to axum 0.8 I stumbled onto this issue.

use axum::{routing::get, Router};

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/", get(|| async { "Hello, World!" }))
        .layer(sentry_tower::NewSentryLayer::new_from_top()); // this fails because the service is not `Sync` 

    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
    axum::serve(listener, app).await.unwrap();
}

With axum 0.8 all Layers & services are expected to be Sync (tokio-rs/axum#2473).

sentry_tower::SentryLayer and ::SentryService are only Sync if the given Request is Sync, which the default axum::request::Request isn't.

So my guess is that every axum user will run into this issue.

Expected Result

Since the Request is only used in a function argument in the HubProvider, I assume that the service / layer could totally be Sync.

Actual Result

error[E0277]: `(dyn HttpBody<Data = axum::body::Bytes, Error = axum::Error> + Send + 'static)` cannot be shared between threads safely
    --> src/main.rs:8:16
     |
8    |         .layer(sentry_tower::NewSentryLayer::new_from_top());
     |          ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn HttpBody<Data = axum::body::Bytes, Error = axum::Error> + Send + 'static)` cannot be shared between thre
ads safely
     |          |
     |          required by a bound introduced by this call
     |

potential solution?

From what I see, the solution could be something like this. It definitely compiles in docs.rs. I'm not sure about what tests would be expected.

@syphar syphar changed the title sentry-tower: using the layer breaks with axum ~0.8 because it's !Sync sentry-tower: using the layer breaks with axum ~0.8 because it's not Sync Jan 4, 2025
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

1 participant