Finish all renderer SQL queries switching to main

Don't switch to main process until all renderer SQL queries are
completed. If we switch while some of them are still running - we can
get SQL_BUSY from concurrent writes in main and renderer processes.
This commit is contained in:
Fedor Indutny 2021-04-01 11:34:28 -07:00 committed by Josh Perez
parent eb97c1194a
commit cf50550936
2 changed files with 10 additions and 2 deletions

View file

@ -2094,7 +2094,7 @@ export async function startApp(): Promise<void> {
); );
} }
window.sqlInitializer.goBackToMainProcess(); await window.sqlInitializer.goBackToMainProcess();
window.Signal.Util.setBatchingStrategy(false); window.Signal.Util.setBatchingStrategy(false);
const attachmentDownloadQueue = window.attachmentDownloadQueue || []; const attachmentDownloadQueue = window.attachmentDownloadQueue || [];

View file

@ -242,7 +242,15 @@ const dataInterface: ClientInterface = {
export default dataInterface; export default dataInterface;
function goBackToMainProcess() { async function goBackToMainProcess(): Promise<void> {
window.log.info('data.goBackToMainProcess: waiting for pending queries');
// Let pending queries finish before we'll give write access to main process.
// We don't want to be writing from two processes at the same time!
await waitForPendingQueries();
window.log.info('data.goBackToMainProcess: switching to main process');
shouldUseRendererProcess = false; shouldUseRendererProcess = false;
} }