=== modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.network_socket.js'
--- old/src/com/goldencode/p2j/ui/client/driver/web/res/p2j.network_socket.js	2025-09-22 05:37:18 +0000
+++ new/src/com/goldencode/p2j/ui/client/driver/web/res/p2j.network_socket.js	2025-09-22 13:19:34 +0000
@@ -7,7 +7,8 @@
 ** -#- -I- --Date-- ------------------------------Description----------------------------------
 ** 001 PMP 20250916 Created initial version.
 **     PMP 20250917 Replaced fragile string replacement with URL object for socket endpoint.
-**     PMP 20250922 Ensured full cleanup by detaching handlers before closing the websocket.
+**     PMP 20250922 Ensured full cleanup by detaching handlers before closing the websocket,
+**                  into the onclose handler.
 */
 /*
 ** This program is free software: you can redistribute it and/or modify
@@ -167,9 +168,16 @@
 
         netSocket.onclose = (event) => 
         {
-            console.log("WebSocket closed. Reason = " + event.reason);
+            console.log("WebSocket closed.", event);
             // If the websocket closed unexpectedly, abort the test with error message.
             p2j.perfTests.notifyClosing();
+
+            //cleanup
+            netSocket.onopen = null;
+            netSocket.onmessage = null;
+            netSocket.onerror = null;
+            netSocket.onclose = null;
+            netSocket = null;
         };
 
 
@@ -187,13 +195,8 @@
     {
         if (netSocket) 
         {
+            console.log("Closing network websocket...");
             netSocket.close();
-            console.log("Closing network websocket...");
-            netSocket.onopen = null;
-            netSocket.onmessage = null;
-            netSocket.onerror = null;
-            netSocket.onclose = null;
-            netSocket = null;
         }
     };
 

