Repository navigation
Build the usage sharing HTTP client on the element's own thread - #189
Merged
Merged
Conversation
The element built its blocking reqwest client on the thread that created it. Building one inside an async runtime panics in a debug build, and a web server usually creates its pipeline inside its runtime. The client is now built by the first send, on the element's background thread.
Merged
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #157
Problem
ShareUsageElement::newbuilt the blockingreqwestclient it sends with on the thread that created the element (share_usage_element.rs L531-L545). In a debug build, building a blocking client inside an async runtime panics with "Cannot drop a runtime in a context where blocking is not allowed", becausereqwestbuilds and drops a runtime of its own to check where it is, and tokio refuses to drop a runtime inside another's async context.A web server built on axum usually creates its pipeline inside its runtime, in
#[tokio::main] async fn main. Usage sharing is on by default in both facade builders, and the README's web example builds its pipeline inside anasync fn(README.md L232-L237). The axum examples avoid the panic only by building the pipeline before the runtime starts, with a comment that says why (dd-web-getting-started-onprem.rs L120-L125).Change
Client::default(), which panics when building fails.ShareUsageElement::newsays the element can be created inside an async runtime.share_usage_is_created_and_used_inside_an_async_runtime, inpipeline-engines-fiftyone/tests/elements.rs, creates the element, processes a request and drops the element inside a current-thread tokio runtime, and checks the local capture server received the record.tokiowith itsrtfeature is a new dev-dependency of the crate for it.How it was verified
On Windows 11 with Rust 1.95.0. The new tests were first run against the base commit 9fe201e, with nothing else changed, using
cargo test -p fiftyone-pipeline-core -p fiftyone-pipeline-engines-fiftyone --no-fail-fast -- --test-threads=1, and each failed as shown.share_usage_is_created_and_used_inside_an_async_runtimepanicked at tokio'sruntime/blocking/shutdown.rs:51:21with "Cannot drop a runtime in a context where blocking is not allowed. This happens when a runtime is dropped from within an asynchronous context."With the change,
cargo fmt --all -- --checkpasses on a local merge of this branch with the six other branches raised alongside it. The test and lint counts on this branch and on that merge are added below as the runs finish.Behaviour that changes
ShareUsageElement::newandwith_defaultsno longer panic inside an async runtime in a debug build.reqweststarts for it, now exist only once the element has a message to send.What remains
reqwestclients as they are created. They are outside this change, so this change alone does not make every facade pipeline safe to build inside a runtime.