Skip to content

Commit

Permalink
[lib] Close tunnelbroker socket when app is in background
Browse files Browse the repository at this point in the history
Summary:
This diff closes tunnelbroker socket when app goes to background in order to prevent messages from decrypting twice and weird socket state.

https://linear.app/comm/issue/ENG-9741/tunnelbroker-socket-onmessage-is-triggered-before-re-opening-socket

Test Plan:
1. Run the app
2. Put the app in the background
3. Send some DMs to the app
4. Bring the app to the foreground
5. Observe in logs that the socket is closed after going to the background and verify that no message is received before closing the socket

Reviewers: tomek, kamil

Reviewed By: kamil

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D13787
  • Loading branch information
graszka22 committed Oct 29, 2024
1 parent ba0f863 commit 603f692
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/tunnelbroker/tunnelbroker-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ function TunnelbrokerProvider(props: Props): React.Node {

const accessToken = useSelector(state => state.commServicesAccessToken);
const userID = useSelector(state => state.currentUserInfo?.id);
const isAppActive = useSelector(
state => state.lifecycleState !== 'background',
);

const [unauthorizedDeviceID, setUnauthorizedDeviceID] =
React.useState<?string>(null);
Expand Down Expand Up @@ -440,6 +443,12 @@ function TunnelbrokerProvider(props: Props): React.Node {
[secondaryTunnelbrokerConnection],
);

React.useEffect(() => {
if (!isAppActive) {
socket.current?.close();
}
}, [isAppActive]);

const addListener = React.useCallback(
(listener: TunnelbrokerSocketListener) => {
listeners.current.add(listener);
Expand Down

0 comments on commit 603f692

Please sign in to comment.