officialasishkumar opened a new issue, #4376:
URL: https://github.com/apache/texera/issues/4376

   ### What happened?
   
   `WorkflowWebsocketService.openWebsocket` subscribes to the internal
   `webSocketResponseSubject` observable to track cluster status and connection 
health:
   
   ```typescript
   // workflow-websocket.service.ts – openWebsocket()
   this.websocketEvent().subscribe(evt => {
     if (evt.type === "ClusterStatusUpdateEvent") {
       this.numWorkers = evt.numWorkers;
     }
     this.updateConnectionStatus(true);
   });
   ```
   
   The returned `Subscription` is never stored, so `closeWebsocket` has no way 
to
   unsubscribe it:
   
   ```typescript
   public closeWebsocket() {
     this.wsWithReconnectSubscription?.unsubscribe(); // only this one is 
cleaned up
     this.websocket?.complete();
     this.updateConnectionStatus(false);
   }
   ```
   
   Every successive call to `openWebsocket` (which happens each time the user 
switches
   workflows or computing units — see `computing-unit-status.service.ts:166`) 
adds
   another live subscriber to the same Subject.
   
   **Consequences:**
   - N calls to `openWebsocket` result in N concurrent handlers firing for every
     WebSocket event.
   - `updateConnectionStatus(true)` is called N times per event (harmless only 
because
     of the internal equality guard, but still wasteful).
   - `numWorkers` is written N times per `ClusterStatusUpdateEvent` update.
   - The closure heap used by each abandoned handler is never released, 
producing a
     memory leak that grows with the length of the user session.
   
   **Expected behavior:** closing the websocket should clean up all 
subscriptions
   created by `openWebsocket`, including the connection-status subscriber, so 
that
   each `openWebsocket/closeWebsocket` cycle is symmetrical and leak-free.
   
   ### How to reproduce?
   
   1. Open the Texera frontend.
   2. Open a workflow and connect to a computing unit (triggers the first 
`openWebsocket`).
   3. Switch to a different workflow or computing unit (triggers a 
`closeWebsocket` + `openWebsocket`).
   4. Repeat several times.
   5. Observe memory growing and duplicate event handling (e.g. with browser 
dev-tools memory profiler or by adding a `console.log` inside the subscriber).
   
   ### Version
   
   1.1.0-incubating (Pre-release/Master)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to