Skip to content

Commit c783ed8

Browse files
committed
Log a special error when try to upload duplicate one-time keys
1 parent 1396738 commit c783ed8

File tree

1 file changed

+22
-2
lines changed
  • crates/matrix-sdk/src/encryption

1 file changed

+22
-2
lines changed

crates/matrix-sdk/src/encryption/mod.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use matrix_sdk_base::crypto::{
4444
use matrix_sdk_common::{executor::spawn, locks::Mutex as StdMutex};
4545
use ruma::{
4646
api::client::{
47+
error::ErrorBody,
4748
keys::{
4849
get_keys, upload_keys, upload_signatures::v3::Request as UploadSignaturesRequest,
4950
upload_signing_keys::v3::Request as UploadSigningKeysRequest,
@@ -85,7 +86,7 @@ use crate::{
8586
client::{ClientInner, WeakClient},
8687
error::HttpResult,
8788
store_locks::CrossProcessStoreLockGuard,
88-
Client, Error, HttpError, Result, Room, TransmissionProgress,
89+
Client, Error, HttpError, Result, Room, RumaApiError, TransmissionProgress,
8990
};
9091

9192
pub mod backups;
@@ -622,7 +623,26 @@ impl Client {
622623
self.keys_query(r.request_id(), request.device_keys.clone()).await?;
623624
}
624625
AnyOutgoingRequest::KeysUpload(request) => {
625-
self.keys_upload(r.request_id(), request).await?;
626+
self.keys_upload(r.request_id(), request).await.inspect_err(|e| {
627+
match e.as_ruma_api_error() {
628+
Some(RumaApiError::ClientApi(e)) if e.status_code == 400 => {
629+
if let ErrorBody::Standard { message, .. } = &e.body {
630+
// This is one of the nastiest errors we can have. The server
631+
// telling us that we already have a one-time key uploaded means
632+
// that we forgot about some of our one-time keys. This will lead to
633+
// UTDs.
634+
if message.starts_with("One time key") {
635+
tracing::error!(
636+
sentry = true,
637+
error_message = message,
638+
"Duplicate one-time keys have been uploaded"
639+
);
640+
}
641+
}
642+
}
643+
_ => {}
644+
}
645+
})?;
626646
}
627647
AnyOutgoingRequest::ToDeviceRequest(request) => {
628648
let response = self.send_to_device(request).await?;

0 commit comments

Comments
 (0)