Skip to content

Commit 2117945

Browse files
committed
[lib] Fix keyserver not present in keyserver store error
Summary: issue: https://linear.app/comm/issue/ENG-5905/uncaught-typeerror-cannot-read-properties-of-undefined-reading The following error was showing up on some peoples consoles: ``` Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'updatesCurrentAsOf') at U7 (prod.4ff39ebc9fcd.build.js:2:4648139) at prod.4ff39ebc9fcd.build.js:2:4683479 at prod.4ff39ebc9fcd.build.js:2:4682129 at y (prod.4ff39ebc9fcd.build.js:2:1767761) at prod.4ff39ebc9fcd.build.js:2:4683981 at Object.dispatch (prod.4ff39ebc9fcd.build.js:2:2405643) at WebSocket.<anonymous> (prod.4ff39ebc9fcd.build.js:2:4669607) ``` The reason was that `setNewSessionActionType` was being dispatched from the Socket without `keyserverID` in payload. The keyserver id is required, but `dispatch` is not typed very well, so flow didn't catch it. This was causing a new keyserver to be added to the keyserver store by the keyserver reducer - a keyserver with id `undefined`. This keyserver was not previously present in the store, so `state.keyserverStore.keyserverInfos[keyserverID].updatesCurrentAsOf` in `baseReducer` would throw. So the fist thing that has to be done, is fixing the payload. Secondly, we have an action that can add a keyserver to the store, and this would also result in this error being thrown. But when `addKeyserverActionType` is dispatched we don't need to update `currentAsOf` or `updatesCurrentAsOf`, so we will just if this out (change in master-reducer.js line 87) Thirdly, we should protect ourselfes from this error in case someone adds some code that can add a keyserver and doesn't update this code (change in master-reducer.js line 109). Test Plan: 1. Tested that the `setNewSessionActionType` action with broken payload indeed causes this error to show up, by dispatching it manually 2. Tested that adding the `keyserverID` to the payload fixes the issue, and the error does not appear (before changes to `baseReducer`) 3. Tested that the code is not executed when `addKeyserverActionType` is dispatched 4. Tested that even if a new keyserver is added by `setNewSessionActionType` with broken payload, the error is not thrown Reviewers: ashoat, kamil, tomek Reviewed By: kamil, tomek Differential Revision: https://phab.comm.dev/D10091
1 parent 06cb756 commit 2117945

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/reducers/master-reducer.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import reduceGlobalThemeInfo from './theme-reducer.js';
2222
import { reduceThreadActivity } from './thread-activity-reducer.js';
2323
import { reduceThreadInfos } from './thread-reducer.js';
2424
import { reduceCurrentUserInfo, reduceUserInfos } from './user-reducer.js';
25+
import { addKeyserverActionType } from '../actions/keyserver-actions.js';
2526
import { siweAuthActionTypes } from '../actions/siwe-actions.js';
2627
import {
2728
registerActionTypes,
@@ -82,7 +83,8 @@ export default function baseReducer<N: BaseNavInfo, T: BaseAppState<N>>(
8283
action.type !== fullStateSyncActionType &&
8384
action.type !== registerActionTypes.success &&
8485
action.type !== logInActionTypes.success &&
85-
action.type !== siweAuthActionTypes.success
86+
action.type !== siweAuthActionTypes.success &&
87+
action.type !== addKeyserverActionType
8688
) {
8789
for (const keyserverID in keyserverStore.keyserverInfos) {
8890
if (
@@ -104,8 +106,9 @@ export default function baseReducer<N: BaseNavInfo, T: BaseAppState<N>>(
104106
};
105107
}
106108
if (
109+
state.keyserverStore.keyserverInfos[keyserverID] &&
107110
keyserverStore.keyserverInfos[keyserverID].updatesCurrentAsOf !==
108-
state.keyserverStore.keyserverInfos[keyserverID].updatesCurrentAsOf
111+
state.keyserverStore.keyserverInfos[keyserverID].updatesCurrentAsOf
109112
) {
110113
const keyserverInfos = { ...keyserverStore.keyserverInfos };
111114
keyserverInfos[keyserverID] = {

lib/socket/socket.react.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ class Socket extends React.PureComponent<Props, State> {
509509
error: null,
510510
logInActionSource:
511511
logInActionSources.socketAuthErrorResolutionAttempt,
512+
keyserverID: ashoatKeyserverID,
512513
},
513514
});
514515
} else if (!recoverySessionChange) {

0 commit comments

Comments
 (0)