Fix: Enhance daemon connection management and retry logic
- Clear socket reference on connection close and error - Ensure reconnection attempts only occur if the user is logged in - Improved logging for reconnection attempts and retry count - Added maximum retry limit with extended wait time after reaching it
This commit is contained in:
@@ -309,23 +309,43 @@ const store = createStore({
|
|||||||
daemonSocket.onclose = (event) => {
|
daemonSocket.onclose = (event) => {
|
||||||
state.daemonConnecting = false;
|
state.daemonConnecting = false;
|
||||||
commit('setDaemonConnectionStatus', 'disconnected');
|
commit('setDaemonConnectionStatus', 'disconnected');
|
||||||
|
|
||||||
|
// Bereinige Socket-Referenz wenn Verbindung geschlossen wurde
|
||||||
|
if (state.daemonSocket === daemonSocket) {
|
||||||
|
state.daemonSocket = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!opened && attemptIndex < protocols.length - 1) {
|
if (!opened && attemptIndex < protocols.length - 1) {
|
||||||
attemptIndex += 1;
|
attemptIndex += 1;
|
||||||
tryConnectWithProtocol();
|
tryConnectWithProtocol();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nur reconnen, wenn Benutzer noch eingeloggt ist
|
||||||
|
if (state.isLoggedIn && state.user) {
|
||||||
dispatch('retryDaemonConnection');
|
dispatch('retryDaemonConnection');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
daemonSocket.onerror = (error) => {
|
daemonSocket.onerror = (error) => {
|
||||||
state.daemonConnecting = false;
|
state.daemonConnecting = false;
|
||||||
commit('setDaemonConnectionStatus', 'error');
|
commit('setDaemonConnectionStatus', 'error');
|
||||||
|
|
||||||
|
// Bereinige Socket-Referenz bei Fehler
|
||||||
|
if (state.daemonSocket === daemonSocket) {
|
||||||
|
state.daemonSocket = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!opened && attemptIndex < protocols.length - 1) {
|
if (!opened && attemptIndex < protocols.length - 1) {
|
||||||
attemptIndex += 1;
|
attemptIndex += 1;
|
||||||
tryConnectWithProtocol();
|
tryConnectWithProtocol();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nur reconnen, wenn Benutzer noch eingeloggt ist
|
||||||
|
if (state.isLoggedIn && state.user) {
|
||||||
dispatch('retryDaemonConnection');
|
dispatch('retryDaemonConnection');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
daemonSocket.addEventListener('message', (event) => {
|
daemonSocket.addEventListener('message', (event) => {
|
||||||
@@ -360,19 +380,44 @@ const store = createStore({
|
|||||||
connectDaemonSocket();
|
connectDaemonSocket();
|
||||||
},
|
},
|
||||||
retryDaemonConnection({ commit, state, dispatch }) {
|
retryDaemonConnection({ commit, state, dispatch }) {
|
||||||
|
// Prüfe ob Benutzer noch eingeloggt ist
|
||||||
|
if (!state.isLoggedIn || !state.user) {
|
||||||
|
console.log('[Daemon] Benutzer nicht eingeloggt, keine Wiederherstellung der Verbindung');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prüfe ob bereits ein Timer läuft
|
||||||
if (state.daemonRetryTimer) {
|
if (state.daemonRetryTimer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maximale Anzahl von Versuchen: 15
|
||||||
|
const maxRetries = 15;
|
||||||
|
if (state.daemonRetryCount >= maxRetries) {
|
||||||
|
console.warn(`[Daemon] Maximale Anzahl von Reconnect-Versuchen (${maxRetries}) erreicht. Warte länger...`);
|
||||||
|
// Warte länger nach maximalen Versuchen (30 Sekunden)
|
||||||
|
state.daemonRetryCount = 0; // Reset für nächsten Zyklus
|
||||||
|
const delay = 30000;
|
||||||
|
state.daemonRetryTimer = setTimeout(() => {
|
||||||
|
state.daemonRetryTimer = null;
|
||||||
|
commit('setDaemonConnectionStatus', 'connecting');
|
||||||
|
dispatch('initializeDaemonSocket');
|
||||||
|
}, delay);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
state.daemonConnecting = false;
|
state.daemonConnecting = false;
|
||||||
state.daemonRetryCount++;
|
state.daemonRetryCount++;
|
||||||
const delay = 5000;
|
const delay = 5000;
|
||||||
console.log(`Daemon: Reconnect-Versuch ${state.daemonRetryCount}, nächster Versuch in ${delay}ms...`);
|
console.log(`[Daemon] Reconnect-Versuch ${state.daemonRetryCount}/${maxRetries}, nächster Versuch in ${delay}ms...`);
|
||||||
|
|
||||||
state.daemonRetryTimer = setTimeout(() => {
|
state.daemonRetryTimer = setTimeout(() => {
|
||||||
state.daemonRetryTimer = null;
|
state.daemonRetryTimer = null;
|
||||||
|
// Prüfe noch einmal, ob Benutzer noch eingeloggt ist
|
||||||
|
if (state.isLoggedIn && state.user) {
|
||||||
commit('setDaemonConnectionStatus', 'connecting');
|
commit('setDaemonConnectionStatus', 'connecting');
|
||||||
dispatch('initializeDaemonSocket');
|
dispatch('initializeDaemonSocket');
|
||||||
|
}
|
||||||
}, delay);
|
}, delay);
|
||||||
},
|
},
|
||||||
setLanguage({ commit }, language) {
|
setLanguage({ commit }, language) {
|
||||||
|
|||||||
Reference in New Issue
Block a user