Repository navigation
[PB-7045] fix: run only one placeholder refresh at a time per sync context - #1604
victor-ferro wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| function createAbortError() { | ||
| const error = new Error('Refresh item placeholders was aborted'); | ||
| error.name = 'AbortError'; | ||
| return error; | ||
| } |
There was a problem hiding this comment.
I dont think we do really need an specific funcion to create an Aborrt error, perhaps a better idea is to have a common Error type and add the "abort error" code so that we can track better this error code, perhaps we already have it. The main idea with this is that we introduce the less amount of code and reuse what we already have, this way you are introducing an error that is only being used here and we will have to maintain just for this specific case.
There was a problem hiding this comment.
Agreed, removed it. Logout calls ctx.abortController.abort() with no argument, so signal.reason is already the standard AbortError
| }; | ||
|
|
||
| export async function refreshItemPlaceholders({ ctx, isFirstExecution }: Props): Promise<Result<boolean, Error>> { | ||
| type RefreshResult = Result<boolean, Error>; |
There was a problem hiding this comment.
This type is not really necessary no? Result<boolean, Error> is as self explanatory as it gets
There was a problem hiding this comment.
True, removed it and used Result<boolean, Error> directly
|
|
||
| /** | ||
| * v2.7.4 Victor Fernandez | ||
| * Startup, remote sync and recovery sync can ask for a refresh at the same time, and every pass loads the whole |
There was a problem hiding this comment.
If im not mistaken, a recovery sync cannot run while a remote sync is in place and vice versa
There was a problem hiding this comment.
i've updated the comment
|



What is Changed / Added
refreshItemPlaceholdersruns at most one placeholder refresh at a time per sync context.isFirstExecution), the refresh runs as a startup refresh, so nothing that only that refresh does is lost.AbortError, which is the error recovery sync already handles.Why
Three refreshes start at the same time on startup. They are requested by the worker startup, the remote sync and the recovery sync, with no lock between them. Each refresh loads the whole local database in memory. On big accounts this makes the app crash with out of memory in the main process.
The running refresh is not reused. Requests that arrive later may come from database changes that refresh did not see, for example the ones from recovery sync.
Tested locally with a real customer database (1.88 M rows), the real code and Electron's 4 GB heap limit. The three startup requests plus a backup were run three times:
main, it crashes all 3 times;What it does not solve:
Summary by CodeRabbit