From a287d5e2721c3bad444e4d370f28f3742e60ab11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?gr=C3=A9goire=20parant?= Date: Thu, 5 May 2022 11:46:59 +0200 Subject: [PATCH] HotFix WebSocket error 1006 (#2063) * Delete cookie posthog Signed-off-by: Gregoire Parant --- front/src/Connexion/ConnectionManager.ts | 27 +++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index bd305413..a7e0f6b9 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -295,7 +295,32 @@ class ConnectionManager { }); connection.connectionErrorStream.subscribe((event: CloseEvent) => { - console.log("connectionErrorStream => An error occurred while connecting to socket server. Retrying"); + console.info( + "An error occurred while connecting to socket server. Retrying => Event: ", + event.reason, + event.code, + event + ); + + //However, Chrome will rarely report any close code 1006 reasons to the Javascript side. + //This is likely due to client security rules in the WebSocket spec to prevent abusing WebSocket. + //(such as using it to scan for open ports on a destination server, or for generating lots of connections for a denial-of-service attack). + // more detail here: https://www.rfc-editor.org/rfc/rfc6455#section-7.4.1 + if (event.code === 1006) { + //check cookies + const cookies = document.cookie.split(";"); + for (const cookie of cookies) { + //check id cookie posthog exist + const numberIndexPh = cookie.indexOf("_posthog="); + if (numberIndexPh !== -1) { + //if exist, remove posthog cookie + document.cookie = + cookie.slice(0, numberIndexPh + 9) + + "; domain=.workadventu.re; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"; + } + } + } + reject( new Error( "An error occurred while connecting to socket server. Retrying. Code: " +