Skip to content

auto_update: Offload update installation to background thread - #58767

Merged
Veykril merged 8 commits into
zed-industries:mainfrom
lingyaochu:auto_update
Jun 8, 2026
Merged

auto_update: Offload update installation to background thread#58767
Veykril merged 8 commits into
zed-industries:mainfrom
lingyaochu:auto_update

Conversation

@lingyaochu

Copy link
Copy Markdown
Collaborator

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Closes #55279

When auto-updating, Zed first downloads the update and then performs the installation. On each platform, this installation phase runs external commands that spawn new processes. These operations can block the thread they run on—especially under heavy system load or when security/antivirus software is active. (An analysis of the blockages on Windows is documented in #55279 (comment)).

This PR moves the installation process to a background thread. This ensures that even if process spawning block, the main UI thread remains responsive.

Release Notes:

  • Fixed a UI freeze that could occur when installing auto-updates.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jun 7, 2026
@zed-community-bot zed-community-bot Bot added community champion Issues filed by our amazing community champions! 🫶 guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions labels Jun 7, 2026
Comment thread crates/auto_update/src/auto_update.rs Outdated
Comment thread crates/auto_update/src/auto_update.rs Outdated
@Veykril Veykril self-assigned this Jun 8, 2026
lingyaochu and others added 2 commits June 8, 2026 15:40
Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
@zed-industries-bot

zed-industries-bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor
Messages
📖

This PR includes links to the following GitHub Issues: #55279
If this PR aims to close an issue, please include a Closes #ISSUE line at the top of the PR body.

Generated by 🚫 dangerJS against e842442

@lingyaochu

lingyaochu commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

#[cfg(test)]
mod tests {
use client::Client;
use clock::FakeSystemClock;
use futures::channel::oneshot;
use gpui::TestAppContext;
use http_client::{FakeHttpClient, Response};
use settings::default_settings;
use std::{
rc::Rc,
sync::{
Arc,
atomic::{self, AtomicBool},
},
};
use tempfile::tempdir;
#[ctor::ctor(unsafe)]
fn init_logger() {
zlog::init_test();
}
use super::*;
pub(super) struct InstallOverride(pub Rc<dyn Fn(&Path, &AsyncApp) -> Result<Option<PathBuf>>>);

InstallOverride is defined in tests with #[cfg(test)], which is conditionally compiled, so cfg!(test) maybe not suitable here.

Revert of the update changes? Or any other suggestions?

@Veykril

Veykril commented Jun 8, 2026

Copy link
Copy Markdown
Member

lets gate the let install_result = ... line then with #[cfg(test)] and #[cfg(not(test))] respectvely instead of doing the branching

Ok(installer_dir.path().join(filename))
}

#[cfg_attr(test, allow(dead_code))]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is added to make the script/clippy happy

@Veykril
Veykril enabled auto-merge June 8, 2026 09:19
@Veykril
Veykril added this pull request to the merge queue Jun 8, 2026
Merged via the queue into zed-industries:main with commit 4b97414 Jun 8, 2026
32 checks passed
@lingyaochu
lingyaochu deleted the auto_update branch June 8, 2026 10:11
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 8, 2026
…dustries#58767)

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes zed-industries#55279

When auto-updating, Zed first downloads the update and then performs the
installation. On each platform, this installation phase runs external
commands that spawn new processes. These operations can block the thread
they run on—especially under heavy system load or when
security/antivirus software is active. (An analysis of the blockages on
Windows is documented in
zed-industries#55279 (comment)).

This PR moves the installation process to a background thread. This
ensures that even if process spawning block, the main UI thread remains
responsive.

Release Notes:

- Fixed a UI freeze that could occur when installing auto-updates.

---------

Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
This was referenced Jun 18, 2026
Vlaaaaaaad pushed a commit to Vlaaaaaaad/zed that referenced this pull request Jul 7, 2026
…#60528)

The unmount of the update disk image was made async-and-detached in
zed-industries#38867, which introduced a race: the installer TempDir was dropped
(running remove_dir_all) while the DMG was still mounted inside it. The
removal failed silently, leaking a zed-auto-update* dir containing the
~140 MB DMG in /private/var/folders on every update.

Now the unmount is awaited before the temp dir is dropped (installation
already runs on the background executor since zed-industries#58767, so this no longer
blocks the UI), with the Drop impl kept as a safety net for early exits
and cancellation. Additionally, stale installer dirs older than 24 hours
are swept from the temp dir when update polling starts, so existing
accumulated leaks get reclaimed.

Closes FR-104
Closes zed-industries#58835

Release Notes:

- Fixed the macOS auto-updater leaking a copy of the downloaded update
in the system temp directory on every update, and added cleanup of
previously leaked files.
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
…dustries#58767)

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes zed-industries#55279

When auto-updating, Zed first downloads the update and then performs the
installation. On each platform, this installation phase runs external
commands that spawn new processes. These operations can block the thread
they run on—especially under heavy system load or when
security/antivirus software is active. (An analysis of the blockages on
Windows is documented in
zed-industries#55279 (comment)).

This PR moves the installation process to a background thread. This
ensures that even if process spawning block, the main UI thread remains
responsive.

Release Notes:

- Fixed a UI freeze that could occur when installing auto-updates.

---------

Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…dustries#58767)

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes zed-industries#55279

When auto-updating, Zed first downloads the update and then performs the
installation. On each platform, this installation phase runs external
commands that spawn new processes. These operations can block the thread
they run on—especially under heavy system load or when
security/antivirus software is active. (An analysis of the blockages on
Windows is documented in
zed-industries#55279 (comment)).

This PR moves the installation process to a background thread. This
ensures that even if process spawning block, the main UI thread remains
responsive.

Release Notes:

- Fixed a UI freeze that could occur when installing auto-updates.

---------

Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…#60528)

The unmount of the update disk image was made async-and-detached in
zed-industries#38867, which introduced a race: the installer TempDir was dropped
(running remove_dir_all) while the DMG was still mounted inside it. The
removal failed silently, leaking a zed-auto-update* dir containing the
~140 MB DMG in /private/var/folders on every update.

Now the unmount is awaited before the temp dir is dropped (installation
already runs on the background executor since zed-industries#58767, so this no longer
blocks the UI), with the Drop impl kept as a safety net for early exits
and cancellation. Additionally, stale installer dirs older than 24 hours
are swept from the temp dir when update polling starts, so existing
accumulated leaks get reclaimed.

Closes FR-104
Closes zed-industries#58835

Release Notes:

- Fixed the macOS auto-updater leaking a copy of the downloaded update
in the system temp directory on every update, and added cleanup of
previously leaked files.
@zelenenka zelenenka removed the guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions label Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement community champion Issues filed by our amazing community champions! 🫶

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI becomes unresponsive while downloading updates

4 participants