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) => {
|
||||
state.daemonConnecting = false;
|
||||
commit('setDaemonConnectionStatus', 'disconnected');
|
||||
|
||||
// Bereinige Socket-Referenz wenn Verbindung geschlossen wurde
|
||||
if (state.daemonSocket === daemonSocket) {
|
||||
state.daemonSocket = null;
|
||||
}
|
||||
|
||||
if (!opened && attemptIndex < protocols.length - 1) {
|
||||
attemptIndex += 1;
|
||||
tryConnectWithProtocol();
|
||||
return;
|
||||
}
|
||||
dispatch('retryDaemonConnection');
|
||||
|
||||
// Nur reconnen, wenn Benutzer noch eingeloggt ist
|
||||
if (state.isLoggedIn && state.user) {
|
||||
dispatch('retryDaemonConnection');
|
||||
}
|
||||
};
|
||||
|
||||
daemonSocket.onerror = (error) => {
|
||||
state.daemonConnecting = false;
|
||||
commit('setDaemonConnectionStatus', 'error');
|
||||
|
||||
// Bereinige Socket-Referenz bei Fehler
|
||||
if (state.daemonSocket === daemonSocket) {
|
||||
state.daemonSocket = null;
|
||||
}
|
||||
|
||||
if (!opened && attemptIndex < protocols.length - 1) {
|
||||
attemptIndex += 1;
|
||||
tryConnectWithProtocol();
|
||||
return;
|
||||
}
|
||||
dispatch('retryDaemonConnection');
|
||||
|
||||
// Nur reconnen, wenn Benutzer noch eingeloggt ist
|
||||
if (state.isLoggedIn && state.user) {
|
||||
dispatch('retryDaemonConnection');
|
||||
}
|
||||
};
|
||||
|
||||
daemonSocket.addEventListener('message', (event) => {
|
||||
@@ -360,19 +380,44 @@ const store = createStore({
|
||||
connectDaemonSocket();
|
||||
},
|
||||
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) {
|
||||
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.daemonRetryCount++;
|
||||
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 = null;
|
||||
commit('setDaemonConnectionStatus', 'connecting');
|
||||
dispatch('initializeDaemonSocket');
|
||||
// Prüfe noch einmal, ob Benutzer noch eingeloggt ist
|
||||
if (state.isLoggedIn && state.user) {
|
||||
commit('setDaemonConnectionStatus', 'connecting');
|
||||
dispatch('initializeDaemonSocket');
|
||||
}
|
||||
}, delay);
|
||||
},
|
||||
setLanguage({ commit }, language) {
|
||||
|
||||
Reference in New Issue
Block a user