Skip to content

Commit

Permalink
[lib] Don't insert username into UserStore when UserInfo missing
Browse files Browse the repository at this point in the history
Summary:
This addresses [ENG-9373](https://linear.app/comm/issue/ENG-9373/peer-user-bs-app-crashes-when-user-a-deletes-account).

What's happening here:

1. When `findUserIdentities` starts, there is a `UserInfo` for this user in the store
2. By the time `findUserIdentitiesActionTypes.success` is reduced, the `UserInfo` is empty, so we end up inserting just the `username` into the store
3. As a result, we end up passing a `UserInfo` without an ID to C++, which causes a crash

Test Plan:
I tested the following 5 times and confirmed that it didn't cause a crash:

1. Create a test account on iOS Simulator
2. Create a test account on Android
3. Send a friend request from Android to iOS (necessary to create a relationship)
4. Delete account on Android

Reviewers: varun, will

Reviewed By: varun

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D13494
  • Loading branch information
Ashoat committed Sep 26, 2024
1 parent 1d09ec4 commit 40d1fe7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/reducers/user-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,16 +369,19 @@ function reduceUserInfos(
];
}
} else if (action.type === findUserIdentitiesActionTypes.success) {
const newUserInfos = action.payload.userInfos.reduce(
(acc, userInfo) => ({
const newUserInfos = action.payload.userInfos.reduce((acc, userInfo) => {
const existingUserInfo = state.userInfos[userInfo.id];
if (!existingUserInfo) {
return acc;
}
return {
...acc,
[userInfo.id]: {
...state.userInfos[userInfo.id],
...existingUserInfo,
username: userInfo.username,
},
}),
{},
);
};
}, {});

const userStoreOps: $ReadOnlyArray<UserStoreOperation> =
convertUserInfosToReplaceUserOps(newUserInfos);
Expand Down

0 comments on commit 40d1fe7

Please sign in to comment.