fix(napi): user_defined_rt can only be used once - #2841
Conversation
Co-authored-by: lynweklm <lynweklm@gmail.com>
|
Cursor Agent can help with this pull request. Just |
How to use the Graphite Merge QueueAdd the label ready-to-merge to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
|
@cursor fix clippy issue |
|
I refactored the Tokio runtime creation logic in
Learn more about Cursor Agents |
Co-authored-by: lynweklm <lynweklm@gmail.com>
|
@cursor Is there a race condition if multiple worker threads try to initialize a custom tokio runtime simultaneously? |
|
I've been looking into the code you provided, specifically the Based on my analysis, there is NO race condition when multiple worker threads try to initialize a custom Tokio runtime simultaneously. This is because While there's no race condition, I did notice a potential logical issue: if multiple threads attempt to set different custom runtimes, only the first one will succeed, and the others will be silently ignored. This isn't a race condition, but it might not be the intended behavior. You might consider documenting this behavior, adding a warning, or making it clear that subsequent calls to Learn more about Cursor Agents |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where a user-defined Tokio runtime in napi-rs could only be used once before becoming unavailable for restarts. The fix introduces a flag to track when a user-defined runtime was originally provided and falls back to a default runtime when the user-defined one is no longer available.
- Adds tracking of whether a user-defined runtime was originally provided
- Modifies runtime creation logic to fall back to default runtime after user-defined runtime is consumed
- Prevents application crashes on restart by ensuring a runtime is always available
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: lynweklm <lynweklm@gmail.com>
|
@cursoragent fix the compile error |
|
I refined the logic for checking user-defined Tokio runtimes within the NAPI-RS crate. This change improves how the
Learn more about Cursor Agents |
Fixes
napi-rsasync runtime restart by falling back to a default runtime after a user-defined runtime is consumed.Previously, the user-defined Tokio runtime was
take()n from its storage on first use, making it unavailable for subsequent restarts after shutdown. Sincetokio::runtime::Runtimeis notClone, this change introduces a flag to track if a user-defined runtime was originally provided. If it was, and it's no longer available (i.e., already consumed and shut down), the system now gracefully falls back to creating a default Tokio runtime, preventing application crashes on restart.