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

Attempt to reestablish a session when it's found to be corrupt. #287

Merged
merged 2 commits into from
Jan 17, 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
55 changes: 46 additions & 9 deletions libsignal-service/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,15 +663,52 @@ where

for device_id in devices {
trace!("sending message to device {}", device_id);
messages.push(
self.create_encrypted_message(
recipient,
unidentified_access,
device_id,
content,
)
.await?,
)
for _attempt in 0..2 {
match self
.create_encrypted_message(
recipient,
unidentified_access,
device_id,
content,
)
.await
{
Ok(message) => {
messages.push(message);
break;
},
Err(
e @ MessageSenderError::ServiceError(
ServiceError::SignalProtocolError(
SignalProtocolError::SessionNotFound(_),
),
),
) => {
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 {
Ok(()) => continue,
Err(_e) => {
tracing::warn!("Failed to delete session for {}, failing message. {}", addr, _e);
return Err(e);
},
}
},
Err(e) => return Err(e),
}
}
}

Ok(messages)
Expand Down