From 2482a1a9cee549b33b7c60c885eb99a22f9e830c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 15 Feb 2023 14:48:36 +0100 Subject: [PATCH 1/2] Add timeout to HTTP requests during `npm info` and `npm fetch` --- crates/zed/src/languages/installation.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/zed/src/languages/installation.rs b/crates/zed/src/languages/installation.rs index c5aff17e56..df28177f0b 100644 --- a/crates/zed/src/languages/installation.rs +++ b/crates/zed/src/languages/installation.rs @@ -39,6 +39,7 @@ pub async fn npm_package_latest_version(name: &str) -> Result { let output = smol::process::Command::new("npm") .args(["-fetch-retry-mintimeout", "2000"]) .args(["-fetch-retry-maxtimeout", "5000"]) + .args(["-fetch-timeout", "5000"]) .args(["info", name, "--json"]) .output() .await @@ -64,6 +65,7 @@ pub async fn npm_install_packages( let output = smol::process::Command::new("npm") .args(["-fetch-retry-mintimeout", "2000"]) .args(["-fetch-retry-maxtimeout", "5000"]) + .args(["-fetch-timeout", "5000"]) .arg("install") .arg("--prefix") .arg(directory) From 5df50e2fc97a92f875c7174a760da5914be03bd5 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 15 Feb 2023 14:52:13 +0100 Subject: [PATCH 2/2] Add timeouts to HTTP client --- crates/client/src/http.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/client/src/http.rs b/crates/client/src/http.rs index 5139bb8d03..0757cebf3a 100644 --- a/crates/client/src/http.rs +++ b/crates/client/src/http.rs @@ -9,7 +9,7 @@ pub use isahc::{ Error, }; use smol::future::FutureExt; -use std::sync::Arc; +use std::{sync::Arc, time::Duration}; pub use url::Url; pub type Request = isahc::Request; @@ -41,7 +41,13 @@ pub trait HttpClient: Send + Sync { } pub fn client() -> Arc { - Arc::new(isahc::HttpClient::builder().build().unwrap()) + Arc::new( + isahc::HttpClient::builder() + .connect_timeout(Duration::from_secs(5)) + .low_speed_timeout(100, Duration::from_secs(5)) + .build() + .unwrap(), + ) } impl HttpClient for isahc::HttpClient {