Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

Updates: a check GitHub never answers gives up after 20 seconds

小睦67b1b1cf879d
diff --git a/crates/rf-app/src/installer.rs b/crates/rf-app/src/installer.rs
index acac295a..9c0d461b 100644
--- a/crates/rf-app/src/installer.rs
+++ b/crates/rf-app/src/installer.rs
@@ -274,6 +274,21 @@ pub fn deltas_are_the_smaller_download(deltas: &[u64], full: u64) -> bool {
!deltas.is_empty() && sum < full
}
+/// How long a check may wait on GitHub before it is called a failure. The update source has no timeout of its own: a connection that
+/// is made and then stalls (a proxy holding the socket, a half-open link) left the card saying "Checking…" until the app was closed
+/// (a user in China, 2026-12-04: `api.github.com` answered its headers and then took over 20 s for the body, and the check never
+/// came back).
+const CHECK_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(20);
+
+/// Runs `f` on a thread of its own and gives up after `timeout`: `None` means it did not return in time, and its result is dropped.
+fn within<T: Send + 'static>(timeout: std::time::Duration, f: impl FnOnce() -> T + Send + 'static) -> Option<T> {
+ let (tx, rx) = std::sync::mpsc::channel();
+ std::thread::spawn(move || {
+ let _ = tx.send(f());
+ });
+ rx.recv_timeout(timeout).ok()
+}
+
/// Looks for an update and, with `download`, downloads it; without, an update found is only told (`State::Available`) and waits
/// for the About page's Download button ([`download_available`]).
///
@@ -295,8 +310,9 @@ pub fn check(download: bool) {
return;
}
set(State::Checking);
- match um.check_for_updates() {
- Ok(UpdateCheck::UpdateAvailable(mut info)) => {
+ let asking = um.clone();
+ match within(CHECK_TIMEOUT, move || asking.check_for_updates()) {
+ Some(Ok(UpdateCheck::UpdateAvailable(mut info))) => {
let deltas: Vec<u64> = info.DeltasToTarget.iter().map(|a| a.Size).collect();
if !deltas.is_empty() && !deltas_are_the_smaller_download(&deltas, info.TargetFullRelease.Size) {
log::info!("update: {} deltas ({:?} bytes) against a full package of {} bytes: taking the full one", deltas.len(), deltas, info.TargetFullRelease.Size);
@@ -311,8 +327,9 @@ pub fn check(download: bool) {
}
fetch(&um, *info);
}
- Ok(_) => set(State::UpToDate),
- Err(e) => set(State::Failed(e.to_string())),
+ Some(Ok(_)) => set(State::UpToDate),
+ Some(Err(e)) => set(State::Failed(e.to_string())),
+ None => set(State::Failed("GitHub did not answer within 20 seconds; check the connection".into())),
}
}
@@ -473,7 +490,8 @@ pub fn count_start(cx: &mut gpui_kit::App) {
#[cfg(test)]
mod tests {
- use super::{DAY_MS, donate_answered, donate_due, is_beta, star_due, takes_betas};
+ use super::{DAY_MS, donate_answered, donate_due, is_beta, star_due, takes_betas, within};
+ use std::time::Duration;
/// Manual, needs the network: the update source's TLS setup (vendor/velopack: Windows' certificate store, issue 121) reaches
/// GitHub. `cargo test -p rf-app --lib installer::tests::github_answers_through_the_windows_store -- --ignored --nocapture`
@@ -499,6 +517,18 @@ mod tests {
assert!(!is_beta(""));
}
+ #[test]
+ fn a_check_that_does_not_come_back_is_given_up_on() {
+ assert_eq!(
+ within(Duration::from_millis(30), || {
+ std::thread::sleep(Duration::from_millis(400));
+ 7
+ }),
+ None
+ );
+ assert_eq!(within(Duration::from_secs(5), || 7), Some(7));
+ }
+
#[test]
fn an_ordinary_copy_takes_betas_only_when_its_switch_is_on_and_a_beta_always_does() {
assert!(!takes_betas(false, "0.6.5"), "the installed copies of today: a beta is never downloaded by itself");