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

rustls-tls-native-roots does blocking IO during .build #2437

Open
chebbyChefNEQ opened this issue Sep 27, 2024 · 3 comments
Open

rustls-tls-native-roots does blocking IO during .build #2437

chebbyChefNEQ opened this issue Sep 27, 2024 · 3 comments

Comments

@chebbyChefNEQ
Copy link

repro
Cargo.toml

[package]
name = "test-rs"
version = "0.1.0"
edition = "2021"

[dependencies]
reqwest = { version = "~0.12", default_features = false, features = ["rustls-tls-native-roots"] }
use reqwest::ClientBuilder;

fn main() {
    for _ in 0..10 {
        let start = std::time::Instant::now();
        ClientBuilder::new().build().unwrap();
        println!("built in: {:?}", start.elapsed());
    }
}

this produces the following flamegraph, which include loading certs std::fs.

Not sure what's a nice solution as wrapping the load in tokio::spawn_blocking would introduce a breaking change.

@chebbyChefNEQ
Copy link
Author

linux
oops forgot the attach the flamegraph

@seanmonstar
Copy link
Owner

Peeking in the source, yep, it does load a file from the disk. Thinking more about what exactly it's doing, that's not surprising. I'd recommend trying to only build one or a couple clients and sharing them.

I suppose one option is that you could load the native cert yourself manually (asynchronously), add it as a root certificate to the reqwest builder, and not use the rustls-tls-native-roots feature.

@chebbyChefNEQ
Copy link
Author

loading the certs manually certainly sounds like a good solution. Let me try that, thanks for the suggestion!

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

2 participants