-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't create static variables containing a tokio::runtime::Handle
There was a bug in the approach implemented in #30. The issue could manifest as a panic with message: "A Tokio 1.x context was found, but it is being shutdown." This would occur in the following scenario: 1. `.compat()` was used within a tokio context other than the fallback runtime. 2. That runtime was shutdown. 3. `.compat()` was used again. The root cause being that we had a `Handle` stored in a `static` global. `Handle`s are weak by design, and cannot prevent the runtime from shutting down. I reverted most of the changes in #30 and instead added a `get_runtime_handle` function. This function attempts to acquire an existing runtime handle with `try_current` before creating a fallback runtime. This should be safe because `try_current` will only succeed within the scope of a tokio runtime context, and it cannot outlive that scope.
- Loading branch information
1 parent
2eaed54
commit 76f47c5
Showing
1 changed file
with
29 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters