There is a race condition bug in the way we setup socket.io when we are replacing the native WebSocket implementation (which is necessary when connecting from Cloud Shell).
The issue is that our websocket.js code, which replaces the native window.WebSocket with our shim, runs after the main.min.js code, which creates the Kernel object.
The Kernel code does not directly call window.WebSocket. Instead, it copies the value of window.WebSocket at the time it was created into a field of the object, and then calls the value of that field.
This means that if we replace the window.WebSocket value before the Kernel object gets created, then our shim works as expected. However, if that replacement does not happen until the Kernel object is created, then the shim will not work.
We have two options to fix this:
- Ensure the
websocket.js code runs before the main.min.js code
or
- Make the
websocket.js code modify the field in the Kernel object.
I'm not sure if the second option is even possible, so I think the first is by far the best choice.
There is a race condition bug in the way we setup socket.io when we are replacing the native WebSocket implementation (which is necessary when connecting from Cloud Shell).
The issue is that our websocket.js code, which replaces the native
window.WebSocketwith our shim, runs after the main.min.js code, which creates theKernelobject.The
Kernelcode does not directly callwindow.WebSocket. Instead, it copies the value ofwindow.WebSocketat the time it was created into a field of the object, and then calls the value of that field.This means that if we replace the
window.WebSocketvalue before theKernelobject gets created, then our shim works as expected. However, if that replacement does not happen until theKernelobject is created, then the shim will not work.We have two options to fix this:
websocket.jscode runs before themain.min.jscodeor
websocket.jscode modify the field in theKernelobject.I'm not sure if the second option is even possible, so I think the first is by far the best choice.