Fix: Improve daemon connection handling and retry logic
- Reset daemon connection state on successful connection and errors - Clear retry timer when connection is established - Enhanced retry logic to prevent multiple simultaneous connection attempts - Improved logging for daemon reconnection attempts
This commit is contained in:
@@ -292,8 +292,12 @@ const store = createStore({
|
||||
|
||||
daemonSocket.onopen = () => {
|
||||
opened = true;
|
||||
state.daemonRetryCount = 0; // Reset retry counter on successful connection
|
||||
state.daemonRetryCount = 0;
|
||||
state.daemonConnecting = false;
|
||||
if (state.daemonRetryTimer) {
|
||||
clearTimeout(state.daemonRetryTimer);
|
||||
state.daemonRetryTimer = null;
|
||||
}
|
||||
commit('setDaemonConnectionStatus', 'connected');
|
||||
const payload = JSON.stringify({
|
||||
event: 'setUserId',
|
||||
@@ -303,8 +307,8 @@ const store = createStore({
|
||||
};
|
||||
|
||||
daemonSocket.onclose = (event) => {
|
||||
state.daemonConnecting = false;
|
||||
commit('setDaemonConnectionStatus', 'disconnected');
|
||||
// Falls Verbindungsaufbau nicht offen war und es noch einen Fallback gibt → nächsten Versuch ohne Subprotokoll
|
||||
if (!opened && attemptIndex < protocols.length - 1) {
|
||||
attemptIndex += 1;
|
||||
tryConnectWithProtocol();
|
||||
@@ -314,8 +318,8 @@ const store = createStore({
|
||||
};
|
||||
|
||||
daemonSocket.onerror = (error) => {
|
||||
state.daemonConnecting = false;
|
||||
commit('setDaemonConnectionStatus', 'error');
|
||||
// Bei Fehler vor Open: Fallback versuchen
|
||||
if (!opened && attemptIndex < protocols.length - 1) {
|
||||
attemptIndex += 1;
|
||||
tryConnectWithProtocol();
|
||||
@@ -340,7 +344,7 @@ const store = createStore({
|
||||
|
||||
commit('setDaemonSocket', daemonSocket);
|
||||
} catch (error) {
|
||||
// Beim Konstruktionsfehler ebenfalls Fallback versuchen
|
||||
state.daemonConnecting = false;
|
||||
if (attemptIndex < protocols.length - 1) {
|
||||
attemptIndex += 1;
|
||||
tryConnectWithProtocol();
|
||||
@@ -355,34 +359,20 @@ const store = createStore({
|
||||
|
||||
connectDaemonSocket();
|
||||
},
|
||||
retryDaemonConnection({ commit, state }) {
|
||||
if (state.daemonRetryTimer || state.daemonConnecting) {
|
||||
return; // Already retrying or connecting
|
||||
}
|
||||
|
||||
const maxRetries = 15;
|
||||
console.log(`Daemon-Reconnect-Versuch ${state.daemonRetryCount + 1}/${maxRetries}`);
|
||||
|
||||
if (state.daemonRetryCount >= maxRetries) {
|
||||
// Nach maxRetries alle 5 Sekunden weiter versuchen
|
||||
console.log('Daemon: Max Retries erreicht, versuche weiter alle 5 Sekunden...');
|
||||
state.daemonRetryTimer = setTimeout(() => {
|
||||
state.daemonRetryCount = 0; // Reset für nächsten Zyklus
|
||||
state.daemonRetryTimer = null;
|
||||
commit('setDaemonConnectionStatus', 'connecting');
|
||||
// Recursive call to retry
|
||||
setTimeout(() => this.dispatch('retryDaemonConnection'), 100);
|
||||
}, 5000);
|
||||
retryDaemonConnection({ commit, state, dispatch }) {
|
||||
if (state.daemonRetryTimer) {
|
||||
return;
|
||||
}
|
||||
|
||||
state.daemonConnecting = false;
|
||||
state.daemonRetryCount++;
|
||||
const delay = 5000; // Alle 5 Sekunden versuchen
|
||||
console.log(`Daemon: Warte ${delay}ms bis zum nächsten Reconnect-Versuch...`);
|
||||
const delay = 5000;
|
||||
console.log(`Daemon: Reconnect-Versuch ${state.daemonRetryCount}, nächster Versuch in ${delay}ms...`);
|
||||
|
||||
state.daemonRetryTimer = setTimeout(() => {
|
||||
state.daemonRetryTimer = null;
|
||||
this.dispatch('initializeDaemonSocket');
|
||||
commit('setDaemonConnectionStatus', 'connecting');
|
||||
dispatch('initializeDaemonSocket');
|
||||
}, delay);
|
||||
},
|
||||
setLanguage({ commit }, language) {
|
||||
|
||||
Reference in New Issue
Block a user