diff --git a/structr-ui/src/main/resources/structr/js/websocket.js b/structr-ui/src/main/resources/structr/js/websocket.js
index <HASH>..<HASH> 100644
--- a/structr-ui/src/main/resources/structr/js/websocket.js
+++ b/structr-ui/src/main/resources/structr/js/websocket.js
@@ -40,7 +40,11 @@ function wsConnect() {
 
     try {
 
-        ws = undefined;
+        if (ws) {
+            ws.close();
+            ws.length = 0;
+        }
+        
         localStorage.removeItem(userKey);
 
         var isEnc = (window.location.protocol === 'https:');
@@ -444,7 +448,10 @@ function wsConnect() {
 
     } catch (exception) {
         log('Error in connect(): ' + exception);
-        ws.close();
+        if (ws) {
+            ws.close();
+            ws.length = 0;
+        }
     }
 
 }
Fixed very annoying bug which caused unlimited WS connections to be triggered in FF when restarting the backend multiple times and not reloading the UI.