officialasishkumar opened a new pull request, #4377:
URL: https://github.com/apache/texera/pull/4377

   ### What changes were proposed in this PR?
   
   `WorkflowWebsocketService.openWebsocket` subscribed to the internal
   `webSocketResponseSubject` observable to track cluster status and mark the
   connection as live, but did not store the returned `Subscription`.  As a
   result, `closeWebsocket` could not unsubscribe it, causing the handler to
   accumulate on every call to `openWebsocket` (e.g. when the user switches
   workflows or computing units).
   
   **Root cause (before):**
   ```typescript
   // openWebsocket() — subscription discarded, never cleaned up
   this.websocketEvent().subscribe(evt => { ... });
   
   // closeWebsocket() — only wsWithReconnectSubscription was torn down
   this.wsWithReconnectSubscription?.unsubscribe();
   ```
   
   **Fix (after):**
   ```typescript
   // openWebsocket()
   this.statusUpdateSubscription = this.websocketEvent().subscribe(evt => { ... 
});
   
   // closeWebsocket()
   this.wsWithReconnectSubscription?.unsubscribe();
   this.statusUpdateSubscription?.unsubscribe();   // ← new
   ```
   
   The new `statusUpdateSubscription` field is declared as `Subscription | 
undefined`;
   the `?.unsubscribe()` call is safely a no-op when `closeWebsocket` is called 
before
   `openWebsocket` was ever invoked.
   
   ### Any related issues, documentation, discussions?
   
   Closes #4376
   
   ### How was this PR tested?
   
   Two new unit tests were added to `workflow-websocket.service.spec.ts`:
   
   1. `"should unsubscribe statusUpdateSubscription when closeWebsocket is 
called"` —
      sets a subscription via the private field (as `openWebsocket` would do) 
and
      confirms `subscription.closed` is `true` after `closeWebsocket`.
   2. `"should not accumulate event subscriptions across multiple 
closeWebsocket calls"` —
      verifies that calling `closeWebsocket` twice does not throw even when the
      subscription is already closed.
   
   The existing service-creation test continues to pass.
   
   ### Was this PR authored or co-authored using generative AI tooling?
   
   No.


-- 
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