Skip to content

Commit 7bc7360

Browse files
committed
Restore WebSocket reconnection timeouts in background script
- for a newly started server, there is a long delay between these two events [Image] ├── apps │ ├── browser │ │ ├── src │ │ │ ├── background │ │ │ │ ├── keep-alive.ts │ │ │ │ ├── main.ts │ │ │ │ └── websocket.ts │ │ │ └── manifest.json │ │ └── webpack.config.ts │ └── editor │ ├── src │ │ ├── extension.ts │ │ ├── services │ │ │ ├── websocket-manager.ts │ │ │ └── websocket-server-process.ts │ │ └── utils │ │ └── shared-token.ts │ └── webpack.config.ts └── packages └── shared └── src └── constants └── websocket.ts
1 parent c29dfde commit 7bc7360

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎apps/browser/src/background/websocket.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const connect_websocket = async (): Promise<void> => {
6464
if (!is_healthy) {
6565
console.debug('Server health check failed, retrying in 5 seconds...')
6666
is_reconnecting = false
67+
setTimeout(check_and_recover_connection, 5000)
6768
return
6869
}
6970

@@ -119,17 +120,19 @@ export const connect_websocket = async (): Promise<void> => {
119120
websocket = null
120121
}
121122
is_reconnecting = false
122-
// Reconnect attempt will be driven by the next alarm tick
123+
setTimeout(check_and_recover_connection, 1000)
123124
}
124125

125126
ws.onerror = () => {
126127
if (websocket === ws) {
127128
websocket = null
128129
}
129130
is_reconnecting = false
131+
setTimeout(check_and_recover_connection, 1000)
130132
}
131133
} catch {
132134
is_reconnecting = false
135+
setTimeout(check_and_recover_connection, 5000)
133136
}
134137
}
135138

0 commit comments

Comments
 (0)