Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sending note to self as primary without secondary devices #339

Merged
merged 5 commits into from
Oct 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ pub enum MessageSenderError {

#[error("Recipient not found: {addr:?}")]
NotFound { addr: ServiceAddress },

#[error("no messages were encrypted: this should not really happen and most likely implies a logic error")]
NoMessagesToSend,
}

pub type GroupV2Id = [u8; GROUP_IDENTIFIER_LEN];
Expand Down Expand Up @@ -553,10 +556,7 @@ where
// this can happen for example when a device is primary, without any secondaries
// and we send a message to ourselves (which is only a SyncMessage { sent: ... })
// addressed to self
warn!(
"no messages were encrypted: this should not really happen and most likely implies a logic error."
);
break;
return Err(MessageSenderError::NoMessagesToSend);
};

let messages = OutgoingPushMessages {
Expand Down Expand Up @@ -908,32 +908,24 @@ where
messages.push(message);
break;
},
Err(
e @ MessageSenderError::ServiceError(
ServiceError::SignalProtocolError(
SignalProtocolError::SessionNotFound(_),
),
Err(MessageSenderError::ServiceError(
ServiceError::SignalProtocolError(
SignalProtocolError::SessionNotFound(addr),
),
) => {
let MessageSenderError::ServiceError(
ServiceError::SignalProtocolError(
SignalProtocolError::SessionNotFound(addr),
),
) = &e
else {
// We can't bind to addr above, because we move into `e`.
unreachable!()
};
)) => {
// SessionNotFound is returned on certain session corruption.
// Since delete_session *creates* a session if it doesn't exist,
// the NotFound error is an indicator of session corruption.
// Try to delete this session, if it gets succesfully deleted, retry. Otherwise, fail.
tracing::warn!("Potential session corruption for {}, deleting session", addr);
match self.protocol_store.delete_session(addr).await {
match self.protocol_store.delete_session(&addr).await {
Ok(()) => continue,
Err(_e) => {
tracing::warn!("Failed to delete session for {}, failing message. {}", addr, _e);
return Err(e);
Err(error) => {
tracing::warn!(%error, %addr, "failed to delete session");
return Err(
SignalProtocolError::SessionNotFound(addr)
.into(),
);
},
}
},
Expand Down
Loading