{"record":{"id":"e0793d1153aef2d6","repo":"seanmonstar/reqwest","slug":"client-new-e0793d","errorCode":null,"errorMessage":"Client::new()","messagePattern":"Client::new\\(\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/blocking/client.rs","lineNumber":1278,"sourceCode":"        Self::new()\n    }\n}\n\nimpl Client {\n    /// Constructs a new `Client`.\n    ///\n    /// # Panic\n    ///\n    /// This method panics if TLS backend cannot be initialized, or the resolver\n    /// cannot load the system configuration.\n    ///\n    /// Use `Client::builder()` if you wish to handle the failure as an `Error`\n    /// instead of panicking.\n    ///\n    /// This method also panics if called from within an async runtime. See docs\n    /// on [`reqwest::blocking`][crate::blocking] for details.\n    pub fn new() -> Client {\n        ClientBuilder::new().build().expect(\"Client::new()\")\n    }\n\n    /// Creates a `ClientBuilder` to configure a `Client`.\n    ///\n    /// This is the same as `ClientBuilder::new()`.\n    pub fn builder() -> ClientBuilder {\n        ClientBuilder::new()\n    }\n\n    /// Convenience method to make a `GET` request to a URL.\n    ///\n    /// # Errors\n    ///\n    /// This method fails whenever supplied `Url` cannot be parsed.\n    pub fn get<U: IntoUrl>(&self, url: U) -> RequestBuilder {\n        self.request(Method::GET, url)\n    }\n","sourceCodeStart":1260,"sourceCodeEnd":1296,"githubUrl":"https://github.com/seanmonstar/reqwest/blob/9f06fd28abe53e5ff84a091825ea5ce8984b51e0/src/blocking/client.rs#L1260-L1296","documentation":"blocking::Client::new() (src/blocking/client.rs:1277-1279) mirrors the async Client::new(): it calls ClientBuilder::new().build().expect(\"Client::new()\"), so any ClientBuilder failure (TLS backend init, system DNS config load, rustls crypto provider missing) panics the process. Additionally, the blocking client wraps an async runtime internally; the doc comment at client.rs:1275-1276 notes that calling blocking::Client methods from inside an async runtime context also panics. The same expect string 'Client::new()' is shared by both clients, so the panic site must be distinguished by which Client you constructed.","triggerScenarios":"Calling reqwest::blocking::Client::new() in a process whose TLS/resolver setup is broken (same set as the async client). Calling reqwest::blocking::get() or any blocking client method from within a tokio / async-std runtime context, because the blocking client spawns its own runtime and panics if one is already present. Using rustls-no-provider without installing a CryptoProvider before the blocking Client::new().","commonSituations":"Calling reqwest::blocking from inside a #[tokio::main] or #[actix_web::main] handler. Mixing a blocking::Client with an async codebase during migration. Minimal containers missing ca-certificates or /etc/resolv.conf. Forgetting the crypto provider install when the no-provider feature is on.","solutions":["Do not call any blocking client method from within an async runtime; switch to reqwest::Client (async) inside async contexts.","Replace blocking::Client::new() with reqwest::blocking::Client::builder().build()? to surface failures as a Result instead of a panic.","Install ca-certificates / provide root certs and ensure /etc/resolv.conf is present in the deployment.","With rustls-no-provider, call rustls::crypto::aws_lc_rs::default_provider().install_default().unwrap() before constructing the blocking client."],"exampleFix":"// before: panics inside a tokio runtime\n#[tokio::main]\nasync fn main() {\n    let resp = reqwest::blocking::get(\"https://example.com\").unwrap();\n}\n\n// after: use the async client inside an async runtime\n#[tokio::main]\nasync fn main() {\n    let resp = reqwest::get(\"https://example.com\").await.unwrap();\n}","handlingStrategy":"try-catch","validationCode":"// No pre-flight check exists; use the fallible builder and keep blocking calls out of async runtimes.\n#[cfg(feature = \"rustls-no-provider\")]\nfn ensure_crypto_provider() {\n    let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();\n}","typeGuard":null,"tryCatchPattern":"// 1) build fallibly\nlet client = match reqwest::blocking::Client::builder().build() {\n    Ok(c) => c,\n    Err(e) => { eprintln!(\"client build failed: {e}\"); std::process::exit(1); }\n};\n// 2) never call blocking client methods from inside #[tokio::main]/async fn;\n//    use reqwest::Client (async) there instead.","preventionTips":["Never call reqwest::blocking::* from within an async runtime; use the async reqwest::Client inside async code.","Use reqwest::blocking::Client::builder().build()? instead of ::new() to avoid panics on TLS/resolver failure.","Install ca-certificates and ensure /etc/resolv.conf exist in the deployment image.","If using rustls-no-provider, install the crypto provider at startup before any blocking::Client::builder()."],"tags":["panic","blocking","tls","async-runtime","builder","initialization"],"backgroundTag":null,"analyzedSha":"9f06fd28abe53e5ff84a091825ea5ce8984b51e0","analyzedAt":"2026-08-10T17:01:13.368Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}