From 7c3c13cecf48219cdcb90dc0b5019686cdd88626 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:46:42 -0700 Subject: fix(install): retry downloads of registry info / tarballs (#26278) Fixes #26085. Adds a basic retry utility with some defaults, starts off with a 100ms wait, then 250ms, then 500ms I've applied the retry in the http client, reusing an existing function, so this also applies to retrying downloads of deno binaries in `upgrade` and `compile`. I can make a separate function that doesn't retry so this doesn't affect `upgrade` and `compile`, but it seemed desirable to have retries there too, so I left it in. --- cli/tools/upgrade.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cli/tools/upgrade.rs') diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index 7f21e6649..b1b09d1a6 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -913,7 +913,7 @@ async fn download_package( // text above which will stay alive after the progress bars are complete let progress = progress_bar.update(""); let maybe_bytes = client - .download_with_progress(download_url.clone(), None, &progress) + .download_with_progress_and_retries(download_url.clone(), None, &progress) .await .with_context(|| format!("Failed downloading {download_url}. The version you requested may not have been built for the current architecture."))?; Ok(maybe_bytes) -- cgit v1.2.3 From a01edb394d2785b7d37da6435bb37381efc376ea Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 25 Oct 2024 15:58:28 -0400 Subject: fix(upgrade): stop running `deno lsp` processes on windows before attempting to replace executable (#26542) --- cli/tools/upgrade.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'cli/tools/upgrade.rs') diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index b1b09d1a6..77a9f72b8 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -579,6 +579,10 @@ pub async fn upgrade( let output_exe_path = full_path_output_flag.as_ref().unwrap_or(¤t_exe_path); + + #[cfg(windows)] + kill_running_deno_lsp_processes(); + let output_result = if *output_exe_path == current_exe_path { replace_exe(&new_exe_path, output_exe_path) } else { @@ -966,6 +970,34 @@ fn check_windows_access_denied_error( }) } +#[cfg(windows)] +fn kill_running_deno_lsp_processes() { + // limit this to `deno lsp` invocations to avoid killing important programs someone might be running + let is_debug = log::log_enabled!(log::Level::Debug); + let get_pipe = || { + if is_debug { + std::process::Stdio::inherit() + } else { + std::process::Stdio::null() + } + }; + let _ = Command::new("powershell.exe") + .args([ + "-Command", + r#"Get-WmiObject Win32_Process | Where-Object { + $_.Name -eq 'deno.exe' -and + $_.CommandLine -match '^(?:\"[^\"]+\"|\S+)\s+lsp\b' +} | ForEach-Object { + if ($_.Terminate()) { + Write-Host 'Terminated:' $_.ProcessId + } +}"#, + ]) + .stdout(get_pipe()) + .stderr(get_pipe()) + .output(); +} + fn set_exe_permissions( current_exe_path: &Path, output_exe_path: &Path, -- cgit v1.2.3 From 01de3317424cc870913dbe85ff3b80eadaf8cc87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 9 Nov 2024 15:19:46 +0000 Subject: perf(upgrade): cache downloaded binaries in DENO_DIR (#26108) Co-authored-by: Divy Srivastava --- cli/tools/upgrade.rs | 69 +++++++++++----------------------------------------- 1 file changed, 14 insertions(+), 55 deletions(-) (limited to 'cli/tools/upgrade.rs') diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index 77a9f72b8..ed1bc06cf 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -6,13 +6,14 @@ use crate::args::Flags; use crate::args::UpgradeFlags; use crate::args::UPGRADE_USAGE; use crate::colors; +use crate::download_deno_binary::archive_name; +use crate::download_deno_binary::download_deno_binary; +use crate::download_deno_binary::BinaryKind; use crate::factory::CliFactory; use crate::http_util::HttpClient; use crate::http_util::HttpClientProvider; use crate::shared::ReleaseChannel; use crate::util::archive; -use crate::util::progress_bar::ProgressBar; -use crate::util::progress_bar::ProgressBarStyle; use crate::version; use async_trait::async_trait; @@ -34,12 +35,8 @@ use std::process::Command; use std::sync::Arc; use std::time::Duration; -const RELEASE_URL: &str = "https://github.com/denoland/deno/releases"; -const CANARY_URL: &str = "https://dl.deno.land/canary"; -const DL_RELEASE_URL: &str = "https://dl.deno.land/release"; - -pub static ARCHIVE_NAME: Lazy = - Lazy::new(|| format!("deno-{}.zip", env!("TARGET"))); +static ARCHIVE_NAME: Lazy = + Lazy::new(|| archive_name(BinaryKind::Deno, env!("TARGET"))); // How often query server for new version. In hours. const UPGRADE_CHECK_INTERVAL: i64 = 24; @@ -532,13 +529,17 @@ pub async fn upgrade( return Ok(()); }; - let download_url = get_download_url( + let binary_path = download_deno_binary( + http_client_provider, + factory.deno_dir()?, + BinaryKind::Deno, + env!("TARGET"), &selected_version_to_upgrade.version_or_hash, requested_version.release_channel(), - )?; - log::info!("{}", colors::gray(format!("Downloading {}", &download_url))); - let Some(archive_data) = download_package(&client, download_url).await? - else { + ) + .await?; + + let Ok(archive_data) = tokio::fs::read(&binary_path).await else { log::error!("Download could not be found, aborting"); std::process::exit(1) }; @@ -881,48 +882,6 @@ fn base_upgrade_url() -> Cow<'static, str> { } } -fn get_download_url( - version: &str, - release_channel: ReleaseChannel, -) -> Result { - let download_url = match release_channel { - ReleaseChannel::Stable => { - format!("{}/download/v{}/{}", RELEASE_URL, version, *ARCHIVE_NAME) - } - ReleaseChannel::Rc => { - format!("{}/v{}/{}", DL_RELEASE_URL, version, *ARCHIVE_NAME) - } - ReleaseChannel::Canary => { - format!("{}/{}/{}", CANARY_URL, version, *ARCHIVE_NAME) - } - ReleaseChannel::Lts => { - format!("{}/v{}/{}", DL_RELEASE_URL, version, *ARCHIVE_NAME) - } - }; - - Url::parse(&download_url).with_context(|| { - format!( - "Failed to parse URL to download new release: {}", - download_url - ) - }) -} - -async fn download_package( - client: &HttpClient, - download_url: Url, -) -> Result>, AnyError> { - let progress_bar = ProgressBar::new(ProgressBarStyle::DownloadBars); - // provide an empty string here in order to prefer the downloading - // text above which will stay alive after the progress bars are complete - let progress = progress_bar.update(""); - let maybe_bytes = client - .download_with_progress_and_retries(download_url.clone(), None, &progress) - .await - .with_context(|| format!("Failed downloading {download_url}. The version you requested may not have been built for the current architecture."))?; - Ok(maybe_bytes) -} - fn replace_exe(from: &Path, to: &Path) -> Result<(), std::io::Error> { if cfg!(windows) { // On windows you cannot replace the currently running executable. -- cgit v1.2.3 From ce778a947e70616b435920fd6f1fc28c4b2a78d1 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Sun, 10 Nov 2024 09:00:44 +0530 Subject: Revert "perf(upgrade): cache downloaded binaries in DENO_DIR" (#26799) Reverts denoland/deno#26108 Tests are flaky on main https://github.com/denoland/deno/commit/01de3317424cc870913dbe85ff3b80eadaf8cc87 --- cli/tools/upgrade.rs | 69 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 14 deletions(-) (limited to 'cli/tools/upgrade.rs') diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index ed1bc06cf..77a9f72b8 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -6,14 +6,13 @@ use crate::args::Flags; use crate::args::UpgradeFlags; use crate::args::UPGRADE_USAGE; use crate::colors; -use crate::download_deno_binary::archive_name; -use crate::download_deno_binary::download_deno_binary; -use crate::download_deno_binary::BinaryKind; use crate::factory::CliFactory; use crate::http_util::HttpClient; use crate::http_util::HttpClientProvider; use crate::shared::ReleaseChannel; use crate::util::archive; +use crate::util::progress_bar::ProgressBar; +use crate::util::progress_bar::ProgressBarStyle; use crate::version; use async_trait::async_trait; @@ -35,8 +34,12 @@ use std::process::Command; use std::sync::Arc; use std::time::Duration; -static ARCHIVE_NAME: Lazy = - Lazy::new(|| archive_name(BinaryKind::Deno, env!("TARGET"))); +const RELEASE_URL: &str = "https://github.com/denoland/deno/releases"; +const CANARY_URL: &str = "https://dl.deno.land/canary"; +const DL_RELEASE_URL: &str = "https://dl.deno.land/release"; + +pub static ARCHIVE_NAME: Lazy = + Lazy::new(|| format!("deno-{}.zip", env!("TARGET"))); // How often query server for new version. In hours. const UPGRADE_CHECK_INTERVAL: i64 = 24; @@ -529,17 +532,13 @@ pub async fn upgrade( return Ok(()); }; - let binary_path = download_deno_binary( - http_client_provider, - factory.deno_dir()?, - BinaryKind::Deno, - env!("TARGET"), + let download_url = get_download_url( &selected_version_to_upgrade.version_or_hash, requested_version.release_channel(), - ) - .await?; - - let Ok(archive_data) = tokio::fs::read(&binary_path).await else { + )?; + log::info!("{}", colors::gray(format!("Downloading {}", &download_url))); + let Some(archive_data) = download_package(&client, download_url).await? + else { log::error!("Download could not be found, aborting"); std::process::exit(1) }; @@ -882,6 +881,48 @@ fn base_upgrade_url() -> Cow<'static, str> { } } +fn get_download_url( + version: &str, + release_channel: ReleaseChannel, +) -> Result { + let download_url = match release_channel { + ReleaseChannel::Stable => { + format!("{}/download/v{}/{}", RELEASE_URL, version, *ARCHIVE_NAME) + } + ReleaseChannel::Rc => { + format!("{}/v{}/{}", DL_RELEASE_URL, version, *ARCHIVE_NAME) + } + ReleaseChannel::Canary => { + format!("{}/{}/{}", CANARY_URL, version, *ARCHIVE_NAME) + } + ReleaseChannel::Lts => { + format!("{}/v{}/{}", DL_RELEASE_URL, version, *ARCHIVE_NAME) + } + }; + + Url::parse(&download_url).with_context(|| { + format!( + "Failed to parse URL to download new release: {}", + download_url + ) + }) +} + +async fn download_package( + client: &HttpClient, + download_url: Url, +) -> Result>, AnyError> { + let progress_bar = ProgressBar::new(ProgressBarStyle::DownloadBars); + // provide an empty string here in order to prefer the downloading + // text above which will stay alive after the progress bars are complete + let progress = progress_bar.update(""); + let maybe_bytes = client + .download_with_progress_and_retries(download_url.clone(), None, &progress) + .await + .with_context(|| format!("Failed downloading {download_url}. The version you requested may not have been built for the current architecture."))?; + Ok(maybe_bytes) +} + fn replace_exe(from: &Path, to: &Path) -> Result<(), std::io::Error> { if cfg!(windows) { // On windows you cannot replace the currently running executable. -- cgit v1.2.3 From 4e899d48cffa95617266dd8f9aef54603a87ad82 Mon Sep 17 00:00:00 2001 From: snek Date: Thu, 14 Nov 2024 13:16:28 +0100 Subject: fix: otel resiliency (#26857) Improving the breadth of collected data, and ensuring that the collected data is more likely to be successfully reported. - Use `log` crate in more places - Hook up `log` crate to otel - Switch to process-wide otel processors - Handle places that use `process::exit` Also adds a more robust testing framework, with a deterministic tracing setting. Refs: https://github.com/denoland/deno/issues/26852 --- cli/tools/upgrade.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cli/tools/upgrade.rs') diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index 77a9f72b8..cb85859f7 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -540,7 +540,7 @@ pub async fn upgrade( let Some(archive_data) = download_package(&client, download_url).await? else { log::error!("Download could not be found, aborting"); - std::process::exit(1) + deno_runtime::exit(1) }; log::info!( -- cgit v1.2.3