Commit b3db209
fix(frontend): unsubscribe connection-status subscription in WorkflowWebsocketService.closeWebsocket (#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`:
"should close the previous status subscription when openWebsocket is
called again" uses a lightweight WebSocket test double, calls
openWebsocket() twice and closeWebsocket() once, and verifies that the
previous statusUpdateSubscription is torn down on each reopen and on
close
The existing service-creation test continues to pass.
### Was this PR authored or co-authored using generative AI tooling?
No.
---------
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Co-authored-by: Meng Wang <125719918+mengw15@users.noreply.github.com>1 parent d547c76 commit b3db209
2 files changed
Lines changed: 63 additions & 1 deletion
File tree
- frontend/src/app/workspace/service/workflow-websocket
Lines changed: 60 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
24 | 62 | | |
25 | 63 | | |
26 | 64 | | |
| |||
34 | 72 | | |
35 | 73 | | |
36 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
37 | 97 | | |
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| 94 | + | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
| |||
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
135 | | - | |
| 137 | + | |
136 | 138 | | |
137 | 139 | | |
138 | 140 | | |
| |||
0 commit comments