Skip to content

Commit

Permalink
[keyserver] Avoid ignorePromiseRejections if isScriptViewer
Browse files Browse the repository at this point in the history
Summary:
When we use `ignorePromiseRejections` inside a script, it can cause problems because the SQL connection can be shut down before the operation concludes.

As such, we have a pattern to `await` in those cases. You can see we're already using that pattern in the same file for `deletionUpdatesPromise`.

Test Plan: Relying on Flow here, as this is a pretty clear and established pattern

Reviewers: tomek, angelika

Reviewed By: tomek

Differential Revision: https://phab.comm.dev/D14176
  • Loading branch information
Ashoat committed Dec 20, 2024
1 parent 172f8c4 commit b84a1b8
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions keyserver/src/deleters/account-deleters.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ async function deleteAccount(viewer: Viewer): Promise<?LogOutResponse> {
(user: UserInfo): boolean => user.id !== deletedUserID,
);

ignorePromiseRejections(deleteUploadsForUser(deletedUserID));
if (viewer.isScriptViewer) {
await deleteUploadsForUser(deletedUserID);
} else {
ignorePromiseRejections(deleteUploadsForUser(deletedUserID));
}

// TODO: if this results in any orphaned orgs, convert them to chats
const deletionQuery = SQL`
Expand Down Expand Up @@ -124,14 +128,17 @@ async function deleteAccount(viewer: Viewer): Promise<?LogOutResponse> {
};
const message = JSON.stringify(reservedUsernameMessage);

ignorePromiseRejections(
(async () => {
const rustAPI = await getRustAPI();
const accountInfo = await fetchOlmAccount('content');
const signature = accountInfo.account.sign(message);
await rustAPI.removeReservedUsername(message, signature);
})(),
);
const removeReservedUsernamePromise = (async () => {
const rustAPI = await getRustAPI();
const accountInfo = await fetchOlmAccount('content');
const signature = accountInfo.account.sign(message);
await rustAPI.removeReservedUsername(message, signature);
})();
if (viewer.isScriptViewer) {
await removeReservedUsernamePromise;
} else {
ignorePromiseRejections(removeReservedUsernamePromise);
}
}

if (anonymousViewerData) {
Expand Down

0 comments on commit b84a1b8

Please sign in to comment.