Compare commits

..
Author SHA1 Message Date
nvrl 506ff32d08 Merge branch 'main' into fix/mount-key-recovery 2026-11-25 02:10:22 +01:00
nvrl 45a41d4e5c fix(core,fuse): keep the mount failure file readable after a downgrade, test the key wait
Mark the wait for key recovery with a separate awaiting_keys field instead
of a null next_attempt, which an older daemon cannot parse. Pin the
missing-key match against a real rpgp decrypt failure, including the
try-every-key path, and test that a parked daemon pings the watchdog until
it is stopped.
2026-11-25 02:00:33 +01:00
nvrl b15f6db802 fix(fuse,cli): wait for key recovery after a cold mount fails 2026-11-24 21:19:52 +01:00
22 changed files with 285 additions and 28 deletions

No files matched your search

+61 -10
View File
@@ -2685,18 +2685,26 @@ fn cmd_daemon(mountpoint: Option<PathBuf>) -> Result<()> {
let error = format!("{e:#}");
let now = unix_now();
let attempts = failure.as_ref().map_or(1, |f| f.attempts.saturating_add(1));
let delay = mount_retry_delay(attempts);
tracing::error!(
error,
attempts,
retry_secs = delay.as_secs(),
"mount failed; retrying"
);
let delay = mount_retry_schedule(&e, attempts);
match delay {
Some(delay) => tracing::error!(
error,
attempts,
retry_secs = delay.as_secs(),
"mount failed; retrying"
),
None => tracing::error!(
error,
attempts,
"account keys could not open My Files; waiting for service restart"
),
}
let record = pdfs_core::mountfail::MountFailure {
error: error.clone(),
since: failure.as_ref().map_or(now, |f| f.since),
attempts,
next_attempt: now + delay.as_secs() as i64,
next_attempt: now + delay.map_or(0, |delay| delay.as_secs() as i64),
awaiting_keys: delay.is_none(),
not_empty: not_empty_cause(&e),
};
if let Err(e) = pdfs_core::mountfail::record(&state_dir, &record) {
@@ -2704,7 +2712,12 @@ fn cmd_daemon(mountpoint: Option<PathBuf>) -> Result<()> {
}
pdfs_fuse::notify_status(&format!("Mount failing: {error}"));
failure = Some(record);
pdfs_fuse::idle_sleep(delay);
// Retry and a successful login restart the service. Keep the
// watchdog alive while parked without contacting Proton.
match delay {
Some(delay) => pdfs_fuse::idle_sleep(delay),
None => return pdfs_fuse::wait_for_restart().context("wait for key recovery"),
}
}
}
}
@@ -2727,6 +2740,20 @@ fn not_empty_cause(error: &anyhow::Error) -> Option<pdfs_core::mountpoint::NotEm
})
}
fn mount_retry_schedule(error: &anyhow::Error, attempts: u32) -> Option<std::time::Duration> {
let root = error.chain().find_map(|cause| {
cause
.downcast_ref::<std::io::Error>()?
.get_ref()?
.downcast_ref::<pdfs_core::mountfail::RootLookup>()
});
if root.is_some_and(|root| root.needs_account_keys()) {
None
} else {
Some(mount_retry_delay(attempts))
}
}
/// How long to wait before mount attempt `attempts + 1`, after `attempts`
/// failures in a row.
///
@@ -4628,7 +4655,11 @@ fn cmd_diagnose() -> Result<()> {
"failing for {}, {} attempt(s): {}",
human_secs(unix_now().saturating_sub(failure.since).max(0) as u64),
failure.attempts,
failure.error
if failure.awaiting_keys {
format!("{} — after recovering your account keys, restart proton-drive.service", failure.error)
} else {
failure.error
}
),
),
None => println!(
@@ -4909,6 +4940,26 @@ mod login_wait_tests {
assert_eq!(mount_retry_delay(u32::MAX).as_secs(), 120);
}
#[test]
fn cold_root_key_failures_wait_for_a_restart() {
use pdfs_core::proton_sdk::{ProtonError, crypto::CryptoError};
for (cause, parked) in [
(ProtonError::KeysLocked, true),
(CryptoError::Decrypt("missing key".into()).into(), true),
(CryptoError::Decrypt("malformed data".into()).into(), false),
(ProtonError::invalid_operation("missing key"), false),
] {
let io = std::io::Error::other(pdfs_core::mountfail::RootLookup(cause));
let error = anyhow::Error::new(io).context("mount failed");
assert_eq!(mount_retry_schedule(&error, 1).is_none(), parked);
}
let io = std::io::Error::from(std::io::ErrorKind::NetworkUnreachable);
assert_eq!(
mount_retry_schedule(&io.into(), 1),
Some(mount_retry_delay(1))
);
}
/// A refusal over a folder with files in it reaches the failure record
/// through the `io::Error` and the context around it (`docs/BUGS.md` B277).
#[test]
+79 -1
View File
@@ -13,6 +13,25 @@ use serde::{Deserialize, Serialize};
/// The file's name inside the state directory.
const FILE_NAME: &str = "mount-failure.json";
/// Failure to fetch My Files on a cold start with no cached root.
#[derive(Debug, thiserror::Error)]
#[error("fetch My Files root: {0}")]
pub struct RootLookup(pub proton_sdk::ProtonError);
impl RootLookup {
pub fn needs_account_keys(&self) -> bool {
use proton_sdk::{ProtonError, crypto::CryptoError};
// SDK 0.12 carries rpgp's `MissingKey` as the text of Decrypt.
// `a_real_missing_key_failure_waits_for_keys` pins that wording, so
// an SDK or rpgp update that changes it fails the test instead of
// silently going back to the retry loop. Never park for an unrelated
// decryption error.
matches!(self.0, ProtonError::KeysLocked)
|| matches!(&self.0, ProtonError::Crypto(CryptoError::Decrypt(reason)) if reason == "missing key")
}
}
/// The last failed mount attempt.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct MountFailure {
@@ -22,8 +41,14 @@ pub struct MountFailure {
pub since: i64,
/// Failed attempts in a row.
pub attempts: u32,
/// Unix seconds of the next attempt.
/// Unix seconds of the next attempt. Meaningless while `awaiting_keys`.
pub next_attempt: i64,
/// The daemon stopped retrying because the account keys cannot open My
/// Files, and waits for a restart after key recovery. A separate field
/// rather than an optional `next_attempt`, so an older version reading
/// the file after a downgrade still understands it.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub awaiting_keys: bool,
/// Set when the mount was refused because the folder already has files in
/// it, so the app can explain that in the user's language. Absent in a
/// file an older daemon wrote.
@@ -68,6 +93,7 @@ mod tests {
since: 1_700_000_000,
attempts: 3,
next_attempt: 1_700_000_040,
awaiting_keys: false,
not_empty: None,
};
record(&dir, &failure).unwrap();
@@ -81,7 +107,59 @@ mod tests {
fn a_failure_an_older_daemon_wrote_still_reads() {
let old = r#"{"error":"missing key","since":1,"attempts":2,"next_attempt":3}"#;
let failure: MountFailure = serde_json::from_str(old).unwrap();
assert_eq!(failure.next_attempt, 3);
assert!(!failure.awaiting_keys);
assert_eq!(failure.not_empty, None);
assert_eq!(failure.attempts, 2);
}
/// An older daemon, after a downgrade, must still read what this one
/// writes while it waits for key recovery.
#[test]
fn a_key_wait_reads_as_a_plain_failure_without_the_new_field() {
#[derive(Deserialize)]
#[allow(dead_code)]
struct OlderFailure {
error: String,
since: i64,
attempts: u32,
next_attempt: i64,
}
let failure = MountFailure {
error: "fetch My Files root: missing key".into(),
since: 1,
attempts: 1,
next_attempt: 1,
awaiting_keys: true,
not_empty: None,
};
let json = serde_json::to_string(&failure).unwrap();
let older: OlderFailure = serde_json::from_str(&json).unwrap();
assert_eq!(older.next_attempt, 1);
let back: MountFailure = serde_json::from_str(&json).unwrap();
assert!(back.awaiting_keys);
}
/// The error a key that is not the message's recipient really produces,
/// not a hand-written payload.
#[test]
fn a_real_missing_key_failure_waits_for_keys() {
use proton_sdk::crypto::{PrivateKey, generate_node_key};
let unlock = |generated: proton_sdk::crypto::GeneratedNodeKey| {
PrivateKey::from_armored(&generated.locked_armored, &generated.passphrase).unwrap()
};
let recipient = unlock(generate_node_key().unwrap());
let stranger = unlock(generate_node_key().unwrap());
let message = recipient.encrypt(b"root share key").unwrap();
let single = stranger.decrypt_armored_message(&message).unwrap_err();
assert!(RootLookup(single.into()).needs_account_keys());
let any = proton_sdk::crypto::decrypt_armored_with_keys(&message, &[stranger]).unwrap_err();
assert!(RootLookup(any.into()).needs_account_keys());
assert!(
!RootLookup(proton_sdk::ProtonError::invalid_operation("missing key"))
.needs_account_keys()
);
}
}
+1
View File
@@ -39,3 +39,4 @@ parking_lot.workspace = true
[dev-dependencies]
tracing-subscriber.workspace = true
tokio = { workspace = true, features = ["test-util"] }
+3 -1
View File
@@ -129,7 +129,9 @@ use mount::{
};
use reads::{BlockFlight, BlockRing, PREFETCH_BUDGET, Prefetch, ReaderSlot, STREAM_BYPASS_MIN};
use state::{Entry, Intervals, PendingRevision, State, StateGuard, WriteHandle};
pub use systemd::{idle_sleep, status as notify_status, stretch_watchdog_for_startup};
pub use systemd::{
idle_sleep, status as notify_status, stretch_watchdog_for_startup, wait_for_restart,
};
use tracing::{debug, error, info, warn};
use transfers::{CountingWriter, JobGuard, OwnedCountingReader, TransferRegistry};
use r#virtual::{
+1 -1
View File
@@ -291,7 +291,7 @@ fn fetch_or_recall_root(
None if start == Start::SessionExpired => Err(std::io::Error::other(format!(
"Proton refused the session ({err}); run `pdfs login`"
))),
None => Err(std::io::Error::other(format!("fetch My Files root: {err}"))),
None => Err(std::io::Error::other(pdfs_core::mountfail::RootLookup(err))),
}
}
+61
View File
@@ -102,6 +102,44 @@ pub fn idle_sleep(duration: Duration) {
}
}
/// Keep a cold daemon available for a service restart after key recovery.
pub fn wait_for_restart() -> std::io::Result<()> {
use tokio::signal::unix::{SignalKind, signal};
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?
.block_on(async {
let mut terminate = signal(SignalKind::terminate())?;
let mut interrupt = signal(SignalKind::interrupt())?;
let stop = async {
tokio::select! {
_ = terminate.recv() => {}
_ = interrupt.recv() => {}
}
};
park_until(stop, Duration::from_secs(10), watchdog_ping).await;
Ok(())
})
}
/// Call `ping` every `every` until `stop` completes. The parked daemon's whole
/// loop, apart from which signals end it.
async fn park_until(
stop: impl std::future::Future<Output = ()>,
every: Duration,
mut ping: impl FnMut(),
) {
let mut tick = tokio::time::interval(every);
tokio::pin!(stop);
loop {
tokio::select! {
_ = &mut stop => return,
_ = tick.tick() => ping(),
}
}
}
/// How long a mount may take to start before the watchdog counts it as hung.
///
/// Startup has no control socket to probe yet, and on a large account it is
@@ -156,3 +194,26 @@ pub(crate) fn watchdog_period() -> Option<Duration> {
let usec: u64 = std::env::var("WATCHDOG_USEC").ok()?.parse().ok()?;
(usec > 0).then(|| Duration::from_micros(usec / 2))
}
#[cfg(test)]
mod tests {
use super::*;
/// A parked daemon keeps the watchdog fed and returns once stopped, so the
/// restart after key recovery is a clean exit, not a kill.
#[test]
fn a_parked_daemon_pings_until_it_is_stopped() {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_time()
.start_paused(true)
.build()
.unwrap();
let pings = std::cell::Cell::new(0);
runtime.block_on(async {
let stop = tokio::time::sleep(Duration::from_secs(35));
park_until(stop, Duration::from_secs(10), || pings.set(pings.get() + 1)).await;
});
// Ticks at 0, 10, 20 and 30 seconds, then the stop at 35.
assert_eq!(pings.get(), 4);
}
}
+9
View File
@@ -1993,6 +1993,15 @@ pub(crate) fn service_unreachable(
offer_not_empty(&ui, found);
}
}
Some(failure) if failure.awaiting_keys => status(
&ui,
"dialog-warning-symbolic",
&gettext("Can't open your Drive"),
&gettext(
"Your account keys could not open My Files. After recovering your keys, choose Retry.",
),
true,
),
Some(failure) => status(
&ui,
"dialog-warning-symbolic",
+11 -2
View File
@@ -1430,6 +1430,7 @@ pub(crate) fn paint_disconnected(ui: &Rc<Ui>) {
match failure {
Some(failure) => SyncState::CannotOpen {
not_empty: failure.not_empty.is_some(),
waiting_for_keys: failure.awaiting_keys,
},
None => SyncState::Disconnected,
},
@@ -1482,6 +1483,7 @@ pub(crate) enum SyncState {
/// it refuses a folder that already has files in it.
CannotOpen {
not_empty: bool,
waiting_for_keys: bool,
},
/// The daemon is running but didn't answer in time.
NotResponding,
@@ -1586,11 +1588,18 @@ fn paint_sync_status(ui: &Rc<Ui>, state: SyncState) {
gettext("Not connected"),
Some(gettext("Proton Drive isn't running")),
),
SyncState::CannotOpen { not_empty } => (
SyncState::CannotOpen {
not_empty,
waiting_for_keys,
} => (
"dialog-warning-symbolic",
Some("warning"),
gettext("Can't open your Drive"),
Some(if not_empty {
Some(if waiting_for_keys {
gettext(
"Your account keys could not open My Files. After recovering your keys, choose Retry.",
)
} else if not_empty {
gettext("Your Proton Drive folder isn't empty")
} else {
gettext("Proton Drive keeps trying to start")
+13 -10
View File
@@ -197,18 +197,21 @@ fn poll_state(socket: &Path, default_mountpoint: &Path) -> DriveState {
// A daemon whose mount fails on every try never opens the
// socket; the app says why (B263).
Ok(s)
if socket
.parent()
.and_then(pdfs_core::mountfail::read)
.is_some() =>
if let Some(failure) = socket.parent().and_then(pdfs_core::mountfail::read) =>
{
(
// Translators: {username} is the Proton account name. The
// service keeps failing to start; the app shows the error.
gettext_f(
"Signed in as {username} — can't open your Drive",
&[("username", &s.username)],
),
if failure.awaiting_keys {
gettext(
"Your account keys could not open My Files. After recovering your keys, choose Retry.",
)
} else {
// Translators: {username} is the Proton account name. The
// service keeps failing to start; the app shows the error.
gettext_f(
"Signed in as {username} — can't open your Drive",
&[("username", &s.username)],
)
},
Phase::Attention,
)
}
+2 -2
View File
@@ -1335,7 +1335,7 @@ and stop.
### B263 — A mount that can never succeed retries every 5 s and tells only the journal
**Status:** Partly fixed. Errors that no retry fixes are not told apart from network errors yet.
**Status:** Partly fixed. A cold root lookup that needs account keys waits for recovery. Other persistent startup errors still back off and retry.
**Found:** 2026-10-31, issue #40: the app showed "Connecting… waiting for the Proton Drive
service" for days, `pdfs diagnose` only reported the control socket missing, and the reporter
uninstalled.
@@ -1363,7 +1363,7 @@ the error is written nowhere a front end can read it.
- The app shows "Can't open your Drive" with the error and a Retry button instead of
"Connecting…". The tray says "Signed in as … — can't open your Drive". `pdfs diagnose` reports
`[FAIL] mount: failing for …`. `systemctl --user status` shows the error as the unit's status.
- Not done: key, `KeysLocked` and 4xx errors still retry like network errors, only less often.
- With no cached root, a locked keychain or a missing decryption key parks the daemon until Retry or a fresh login restarts the service (#40). Other crypto and HTTP errors still use the bounded retry schedule.
**Test:** `a_failing_mount_backs_off_to_a_ceiling` in `pdfs-cli`;
`a_recorded_failure_reads_back_until_cleared` in `pdfs-core`. On 2026-10-31 a second
+1
View File
@@ -11,6 +11,7 @@ scratch (user data in `staging/` and `recovery/` is never touched by this).
## [Unreleased]
- A cold mount whose account keys cannot open My Files waits for Retry or a fresh sign-in (#40).
- Sign-in failures with Proton code 2028 now give consistent recovery guidance in the desktop app and CLI (#39).
## [3.10.0] — 2026-11-22
+7 -1
View File
@@ -162,7 +162,13 @@ session before it shows your files.
### `fetch My Files root: … failed to decrypt: missing key` in the log
Your account keys cannot open your Drive, which happens after a password reset: Proton locks the
If Drive on the web opens your files, run `pdfs diagnose` and check the **Keys** section.
A missing address key can prevent My Files from opening even when sign-in succeeded. On a
cold start with no cached root the daemon waits for key recovery. After recovering your keys,
choose **Retry** in the app or run `systemctl --user restart proton-drive.service`. If it still
fails, include the client version and the redacted Keys findings in your report.
If the web app also shows locked files after a password reset, Proton locks the
files that were encrypted with the old keys. Since 3.4.1 the client then starts a new, empty My
files. Your old files are still there, locked: open [drive.proton.me](https://drive.proton.me) and
restore them with your previous password. If your files are not locked and the error stays, run
Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

+4
View File
@@ -57,6 +57,10 @@ msgstr "%-d. %b %Y"
msgid "%A, %B %-d, %Y, %H:%M"
msgstr "%A, %-d. %B %Y, %H:%M"
#: crates/pdfs-gui/src/app/main.rs crates/pdfs-gui/src/app/pages/status.rs crates/pdfs-gui/src/main.rs
msgid "Your account keys could not open My Files. After recovering your keys, choose Retry."
msgstr "Deine Kontoschlüssel konnten „Meine Dateien“ nicht öffnen. Stelle die Schlüssel wieder her und wähle „Erneut versuchen“."
#: crates/pdfs-gui/src/app/main.rs:961
#: crates/pdfs-gui/src/app/pages/activity_text.rs:543
#: crates/pdfs-gui/src/app/pages/browser.rs:473
+4
View File
@@ -57,6 +57,10 @@ msgstr "%-d %b %Y"
msgid "%A, %B %-d, %Y, %H:%M"
msgstr "%A %-d %B %Y, %H:%M"
#: crates/pdfs-gui/src/app/main.rs crates/pdfs-gui/src/app/pages/status.rs crates/pdfs-gui/src/main.rs
msgid "Your account keys could not open My Files. After recovering your keys, choose Retry."
msgstr "Your account keys could not open My Files. After recovering your keys, choose Retry."
#: crates/pdfs-gui/src/app/main.rs:961
#: crates/pdfs-gui/src/app/pages/activity_text.rs:543
#: crates/pdfs-gui/src/app/pages/browser.rs:473
+4
View File
@@ -57,6 +57,10 @@ msgstr "%-d %b %Y"
msgid "%A, %B %-d, %Y, %H:%M"
msgstr "%A, %-d de %B de %Y, %H:%M"
#: crates/pdfs-gui/src/app/main.rs crates/pdfs-gui/src/app/pages/status.rs crates/pdfs-gui/src/main.rs
msgid "Your account keys could not open My Files. After recovering your keys, choose Retry."
msgstr "Las claves de tu cuenta no pudieron abrir Mis archivos. Tras recuperarlas, selecciona Reintentar."
#: crates/pdfs-gui/src/app/main.rs:961
#: crates/pdfs-gui/src/app/pages/activity_text.rs:543
#: crates/pdfs-gui/src/app/pages/browser.rs:473
+4
View File
@@ -57,6 +57,10 @@ msgstr "%-d %b %Y"
msgid "%A, %B %-d, %Y, %H:%M"
msgstr "%A %-d %B %Y à %H:%M"
#: crates/pdfs-gui/src/app/main.rs crates/pdfs-gui/src/app/pages/status.rs crates/pdfs-gui/src/main.rs
msgid "Your account keys could not open My Files. After recovering your keys, choose Retry."
msgstr "Les clés de votre compte n’ont pas pu ouvrir Mes fichiers. Après les avoir récupérées, choisissez Réessayer."
#: crates/pdfs-gui/src/app/main.rs:961
#: crates/pdfs-gui/src/app/pages/activity_text.rs:543
#: crates/pdfs-gui/src/app/pages/browser.rs:473
+4
View File
@@ -57,6 +57,10 @@ msgstr "%-d %b %Y"
msgid "%A, %B %-d, %Y, %H:%M"
msgstr "%A %-d %B %Y, %H:%M"
#: crates/pdfs-gui/src/app/main.rs crates/pdfs-gui/src/app/pages/status.rs crates/pdfs-gui/src/main.rs
msgid "Your account keys could not open My Files. After recovering your keys, choose Retry."
msgstr "Le chiavi del tuo account non hanno potuto aprire I miei file. Dopo averle recuperate, scegli Riprova."
#: crates/pdfs-gui/src/app/main.rs:961
#: crates/pdfs-gui/src/app/pages/activity_text.rs:543
#: crates/pdfs-gui/src/app/pages/browser.rs:473
+4
View File
@@ -57,6 +57,10 @@ msgstr "%-d %b %Y"
msgid "%A, %B %-d, %Y, %H:%M"
msgstr "%A %-d %B %Y, %H:%M"
#: crates/pdfs-gui/src/app/main.rs crates/pdfs-gui/src/app/pages/status.rs crates/pdfs-gui/src/main.rs
msgid "Your account keys could not open My Files. After recovering your keys, choose Retry."
msgstr "Je accountsleutels konden Mijn bestanden niet openen. Herstel je sleutels en kies Opnieuw proberen."
#: crates/pdfs-gui/src/app/main.rs:961
#: crates/pdfs-gui/src/app/pages/activity_text.rs:543
#: crates/pdfs-gui/src/app/pages/browser.rs:473
+4
View File
@@ -60,6 +60,10 @@ msgstr ""
msgid "%A, %B %-d, %Y, %H:%M"
msgstr ""
#: crates/pdfs-gui/src/app/main.rs crates/pdfs-gui/src/app/pages/status.rs crates/pdfs-gui/src/main.rs
msgid "Your account keys could not open My Files. After recovering your keys, choose Retry."
msgstr ""
#: crates/pdfs-gui/src/app/main.rs:961
#: crates/pdfs-gui/src/app/pages/activity_text.rs:543
#: crates/pdfs-gui/src/app/pages/browser.rs:473
+4
View File
@@ -59,6 +59,10 @@ msgstr "%-d %b %Y"
msgid "%A, %B %-d, %Y, %H:%M"
msgstr "%A, %-d %B %Y, %H:%M"
#: crates/pdfs-gui/src/app/main.rs crates/pdfs-gui/src/app/pages/status.rs crates/pdfs-gui/src/main.rs
msgid "Your account keys could not open My Files. After recovering your keys, choose Retry."
msgstr "Klucze konta nie pozwoliły otworzyć sekcji Moje pliki. Po odzyskaniu kluczy wybierz Ponów próbę."
#: crates/pdfs-gui/src/app/main.rs:961
#: crates/pdfs-gui/src/app/pages/activity_text.rs:543
#: crates/pdfs-gui/src/app/pages/browser.rs:473
+4
View File
@@ -57,6 +57,10 @@ msgstr "%-d de %b de %Y"
msgid "%A, %B %-d, %Y, %H:%M"
msgstr "%A, %-d de %B de %Y, %H:%M"
#: crates/pdfs-gui/src/app/main.rs crates/pdfs-gui/src/app/pages/status.rs crates/pdfs-gui/src/main.rs
msgid "Your account keys could not open My Files. After recovering your keys, choose Retry."
msgstr "As chaves da sua conta não conseguiram abrir Meus arquivos. Após recuperá-las, selecione Tentar novamente."
#: crates/pdfs-gui/src/app/main.rs:961
#: crates/pdfs-gui/src/app/pages/activity_text.rs:543
#: crates/pdfs-gui/src/app/pages/browser.rs:473