Skip to content

Commit

Permalink
[web][native] Fix retrying sending message when having device without…
Browse files Browse the repository at this point in the history
… keys

Summary:
https://linear.app/comm/issue/ENG-10141/retrying-message-on-prod-cause-it-sending-multiple-times

To reproduce have a device in a "broken" state (? instead of web/mobile icon). Send a message. It will
fail with log "Keys missing for device ..." but the message will be delivered. Showing that the delivery failed
is ok (we couldn't deliver to the broken device) but after retrying the message will be delivered again and
the other user will see duplicated messages.

The exception is thrown in function returned from `useInputStateContainerSendTextMessage`. `failedOutboundP2PMessageIDs` is
set correctly here. But then the exception is caught in `sendTextMessageAction` and re-thrown without setting `failedOutboundP2PMessageIDs`.
`failedOutboundP2PMessageIDs` is then used do determine how we should resend the message.
Therefore setting `failedOutboundP2PMessageIDs` in `sendTextMessageAction` fixes the bug.

Test Plan:
1. Have a "broken" device (by logging out with v1 flow or by failing to connect the device)
2. Send a message and retry.
3. Verify the other user has no duplicated messages.

Reviewers: tomek, kamil

Reviewed By: kamil

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D14289
  • Loading branch information
graszka22 committed Feb 10, 2025
1 parent a38a6e8 commit 883e1ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions native/input/input-state-container.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ class InputStateContainer extends React.PureComponent<Props, State> {
this.pendingSidebarCreationMessageLocalIDs.delete(localID);
return result;
} catch (e) {
if (e instanceof SendMessageError) {
throw e;
}
const exceptionMessage = getMessageForException(e) ?? '';
if (exceptionMessage === 'invalid_csat') {
void this.props.invalidTokenLogOut();
Expand Down Expand Up @@ -613,6 +616,9 @@ class InputStateContainer extends React.PureComponent<Props, State> {
this.pendingSidebarCreationMessageLocalIDs.delete(localID);
return result;
} catch (e) {
if (e instanceof SendMessageError) {
throw e;
}
const exceptionMessage = getMessageForException(e) ?? '';
throw new SendMessageError(
`Exception when sending text message: ${exceptionMessage}`,
Expand Down
6 changes: 6 additions & 0 deletions web/input/input-state-container.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ class InputStateContainer extends React.PureComponent<Props, State> {
});
return result;
} catch (e) {
if (e instanceof SendMessageError) {
throw e;
}
const exceptionMessage = getMessageForException(e) ?? '';
if (exceptionMessage === 'invalid_csat') {
void this.props.invalidTokenLogOut();
Expand Down Expand Up @@ -1385,6 +1388,9 @@ class InputStateContainer extends React.PureComponent<Props, State> {
this.pendingSidebarCreationMessageLocalIDs.delete(localID);
return result;
} catch (e) {
if (e instanceof SendMessageError) {
throw e;
}
const exceptionMessage = getMessageForException(e) ?? '';
throw new SendMessageError(
`Exception while sending text message: ${exceptionMessage}`,
Expand Down

0 comments on commit 883e1ca

Please sign in to comment.