-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(rust): Add warning about #[tokio::main] #7633
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
lizokm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made some language tweaks, otherwise this looks good!
src/platforms/rust/index.mdx
Outdated
|
|
||
| ### Async main function | ||
|
|
||
| The Sentry client must be initialized before any async runtime is started or threads are spawned. Unfortunately, this makes it impossible to use macros such as `#[tokio::main]` or `#[actix_web::main]`, because they start the runtime first. Thus, instead of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The Sentry client must be initialized before any async runtime is started or threads are spawned. Unfortunately, this makes it impossible to use macros such as `#[tokio::main]` or `#[actix_web::main]`, because they start the runtime first. Thus, instead of | |
| The Sentry client must be initialized before any async runtime is started, otherwise threads will be spawned. This means you'll have to avoid using macros such as `#[tokio::main]` or `#[actix_web::main]`, because they start the runtime first. So rather than doing this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, here my formulation was clearly ambiguous. I meant "The Sentry client must be initialized before (any async runtime is started or threads are spawned)".
How does
The Sentry client must be initialized before starting an async runtime or spawning threads.
sound?
Co-authored-by: Liza Mock <[email protected]>
Co-authored-by: Liza Mock <[email protected]>
Co-authored-by: Liza Mock <[email protected]>
Co-authored-by: Liza Mock <[email protected]>
Swatinem
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this sounds very good.
If you want to be very explicit about whats going on, you can also explain the reasoning:
Each spawned thread inherits its Sentry Hub from the main thread. Thus, sentry::init has to happen on the main thread before any other threads are being spawned.
|
@lizokm I've rewritten the paragraph under |
Pre-merge checklist
If you work at Sentry, you're able to merge your own PR without review, but please don't unless there's a good reason.
Description of changes
This warns users not to use macros like
#[tokio::main]or#[actix_web::main]and explains how to manually write an "async" main function.Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
Extra resources