Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(rnd): Fix JS event-loop freeze caused by websocket connection retry (#7861)

Zamil Majdyc719e4f1774b
diff --git a/rnd/autogpt_builder/src/lib/autogpt-server-api/client.ts b/rnd/autogpt_builder/src/lib/autogpt-server-api/client.ts
index 1d45096816..9801149afd 100644
--- a/rnd/autogpt_builder/src/lib/autogpt-server-api/client.ts
+++ b/rnd/autogpt_builder/src/lib/autogpt-server-api/client.ts
@@ -227,13 +227,21 @@ export default class AutoGPTServerAPI {
sendWebSocketMessage<M extends keyof WebsocketMessageTypeMap>(
method: M,
data: WebsocketMessageTypeMap[M],
+ callCount = 0,
) {
if (this.webSocket && this.webSocket.readyState === WebSocket.OPEN) {
this.webSocket.send(JSON.stringify({ method, data }));
} else {
- this.connectWebSocket().then(() =>
- this.sendWebSocketMessage(method, data),
- );
+ this.connectWebSocket().then(() => {
+ callCount == 0
+ ? this.sendWebSocketMessage(method, data, callCount + 1)
+ : setTimeout(
+ () => {
+ this.sendWebSocketMessage(method, data, callCount + 1);
+ },
+ 2 ** (callCount - 1) * 1000,
+ );
+ });
}
}