Skip to content

Commit 9a41573

Browse files
server: Don't consume the keyring if we fail to unlock
Otherwise we end up with no keyring associated to a collection causing a panic when we re-try to unlock it
1 parent 6d9ce61 commit 9a41573

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

server/src/collection.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,22 @@ impl Collection {
492492
custom_service_error("Cannot unlock collection without a secret")
493493
})?;
494494

495-
let unlocked = locked_kr.unlock(secret).await.map_err(|err| {
496-
custom_service_error(&format!("Failed to unlock keyring: {err}"))
497-
})?;
495+
let keyring_path = locked_kr.path().map(|p| p.to_path_buf());
496+
497+
let unlocked = match locked_kr.unlock(secret).await {
498+
Ok(unlocked) => unlocked,
499+
Err(err) => {
500+
// Reload the locked keyring from disk before returning error
501+
if let Some(path) = keyring_path {
502+
if let Ok(reloaded) = oo7::file::LockedKeyring::load(&path).await {
503+
*keyring_guard = Some(Keyring::Locked(reloaded));
504+
}
505+
}
506+
return Err(custom_service_error(&format!(
507+
"Failed to unlock keyring: {err}"
508+
)));
509+
}
510+
};
498511

499512
let items = self.items.lock().await;
500513
for item in items.iter() {

0 commit comments

Comments
 (0)