mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 20:44:32 -05:00
🐛 Fix Initializing the connection to the local database hang (#4375)
* fix initializing to the local db * release notes
This commit is contained in:
@@ -96,11 +96,15 @@ function connectWorker(worker, onOpen, onError) {
|
||||
// ready to handle messages.
|
||||
if (msg.type === 'connect') {
|
||||
// Send any messages that were queued while closed
|
||||
if (messageQueue.length > 0) {
|
||||
if (messageQueue?.length > 0) {
|
||||
messageQueue.forEach(msg => worker.postMessage(msg));
|
||||
messageQueue = null;
|
||||
}
|
||||
|
||||
// signal to the backend that we're connected to it
|
||||
globalWorker.postMessage({
|
||||
name: 'client-connected-to-backend',
|
||||
});
|
||||
onOpen();
|
||||
} else if (msg.type === 'app-init-failure') {
|
||||
onError(msg);
|
||||
|
||||
@@ -44,6 +44,12 @@ export const init: T.Init = function (serverChn, handlers) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.name === 'client-connected-to-backend') {
|
||||
// the client is indicating that it is connected to this backend. Stop attempting to connect
|
||||
clearInterval(reconnectToClientInterval);
|
||||
return;
|
||||
}
|
||||
|
||||
const { id, name, args, undoTag, catchErrors } = msg;
|
||||
|
||||
if (handlers[name]) {
|
||||
@@ -98,7 +104,19 @@ export const init: T.Init = function (serverChn, handlers) {
|
||||
false,
|
||||
);
|
||||
|
||||
serverChannel.postMessage({ type: 'connect' });
|
||||
const RECONNECT_INTERVAL_MS = 200;
|
||||
const MAX_RECONNECT_ATTEMPTS = 500;
|
||||
let reconnectAttempts = 0;
|
||||
|
||||
const reconnectToClientInterval = setInterval(() => {
|
||||
serverChannel.postMessage({ type: 'connect' });
|
||||
reconnectAttempts++;
|
||||
if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
|
||||
// Failed to connect to client - signal server error
|
||||
send('server-error');
|
||||
clearInterval(reconnectToClientInterval);
|
||||
}
|
||||
}, RECONNECT_INTERVAL_MS);
|
||||
};
|
||||
|
||||
export const send: T.Send = function (name, args) {
|
||||
|
||||
6
upcoming-release-notes/4375.md
Normal file
6
upcoming-release-notes/4375.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [MikesGlitch]
|
||||
---
|
||||
|
||||
Prevent the app getting stuck on the "Initializing the connection to the local database..." screen
|
||||
Reference in New Issue
Block a user