eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
19.29k stars 2.45k forks source link

The browser-only Theia example application still tries to create a WebSocket connection #13820

Closed lessmost closed 2 weeks ago

lessmost commented 2 weeks ago

Bug Description:

The browser-only Theia example application still tries to create a WebSocket connection.

Steps to Reproduce:

  1. Clone the Theia repository
git clone https://github.com/eclipse-theia/theia.git
  1. Build and run browser-only sample:
yarn
yarn download:plugins
yarn browser-only build
yarn browser-only start
  1. Visit http://localhost:3000, open dev tools and can find request like

http://localhost:3000/socket.io/?EIO=4&transport=polling&t=P0cgjyV

and wait for a while, there should be a lots of socket.io request 404 error

截屏2024-06-17 23 54 43

Possible Cause

  1. The socket.io request is triggered by WebSocketConnectionSource:createWebSocket, which is triggered by postConstruct in WebSocketConnectionSource.

  2. In electron-messaging-frontend-module.ts which in included by the Browser-only Theia application, ElectronWebSocketConnectionSource is first bound to WebSocketConnectionSource at L36, but also bound as a FrontendApplicationContribution at L74

  3. In messaging-frontend-only-module.ts, although WebSocketConnectionSource is unbind at L24, the ElectronWebSocketConnectionSource FrontendApplicationContribution multiInject still exists. So when application start, ElectronWebSocketConnectionSource will be initialized anyway.

Maybe we can separate ElectronWebSocketConnectionSource from FrontendApplicationContribution and close the socket by an dynamic FrontendApplicationContribution?

#L74

-    bind(FrontendApplicationContribution).toService(ElectronWebSocketConnectionSource);
+    bind(FrontendApplicationContribution).toDynamicValue(ctx => {
+        return {
+            onStop: () => {
+                const websocketConnectionSource = ctx.container.get(WebSocketConnectionSource);
+                websocketConnectionSource.socket.close();
+            }
+        }
+    });

Additional Information

sdirix commented 2 weeks ago

Hi @lessmost,

Thanks for the report and analysis.

2. ElectronWebSocketConnectionSource is first bound to WebSocketConnectionSource at L36, but also bound as a FrontendApplicationContribution at L74

The electron code should never end up in the browser-only case as it's not needed there. So the cause of the issue seems to be this check in the frontend-generator which erroneously ends up in the electron path for browser-only.