Skip to content

Prevent re-opening websocket connections on metadata update - #3093

Merged
shengquan-ni merged 4 commits into
masterfrom
shengquan-fix-duplicated-console
Nov 20, 2024
Merged

shengquan-ni merged 4 commits into
masterfrom
shengquan-fix-duplicated-console

Conversation

@shengquan-ni

@shengquan-ni shengquan-ni commented Nov 20, 2024 •

Copy link
Copy Markdown
Contributor

This PR fixes #3085. The issue is caused by a call of this.workflowActionService.setWorkflowMetadata(updatedWorkflow); in persistWorkflow. This call caused the WebSocket service to detect a workflow metadata update and reopen the WebSocket unnecessarily. Therefore, the bug can be consistently reproduced by hitting the save button on the workflow canvas.

This PR introduces a logic check to skip reopening the WebSocket if the wid remains unchanged, preventing redundant reconnections.

@aglinxinyuan aglinxinyuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@shengquan-ni shengquan-ni changed the title Prevent re-open websocket connections on metadata update Prevent re-opening websocket connections on metadata update Nov 20, 2024
@shengquan-ni
shengquan-ni merged commit 333a5b2 into master Nov 20, 2024
@shengquan-ni
shengquan-ni deleted the shengquan-fix-duplicated-console branch November 20, 2024 22:37
PurelyBlank pushed a commit that referenced this pull request Dec 4, 2024
This PR fixes #3085. The issue is caused by a call of
`this.workflowActionService.setWorkflowMetadata(updatedWorkflow);` in
`persistWorkflow`. This call caused the WebSocket service to detect a
workflow metadata update and reopen the WebSocket unnecessarily.
Therefore, the bug can be consistently reproduced by hitting the save
button on the workflow canvas.

This PR introduces a logic check to skip reopening the WebSocket if the
wid remains unchanged, preventing redundant reconnections.
@Yicong-Huang Yicong-Huang added fix and removed bug labels Oct 4, 2025
SarahAsad23 pushed a commit to madisonmlin/texera that referenced this pull request May 20, 2026
)

This PR fixes apache#3085. The issue is caused by a call of
`this.workflowActionService.setWorkflowMetadata(updatedWorkflow);` in
`persistWorkflow`. This call caused the WebSocket service to detect a
workflow metadata update and reopen the WebSocket unnecessarily.
Therefore, the bug can be consistently reproduced by hitting the save
button on the workflow canvas.

This PR introduces a logic check to skip reopening the WebSocket if the
wid remains unchanged, preventing redundant reconnections.
kunwp1 added a commit to kunwp1/texera that referenced this pull request Jun 8, 2026
…rd (apache#3120)

WorkflowWebsocketService, ComputingUnitStatusService, and the execution-session services (WorkflowStatusService, ExecuteWorkflowService, WorkflowConsoleService, WorkflowResultService) are all root-scoped singletons, so their state outlived the workspace. WorkspaceComponent.ngOnDestroy cleared the workflow graph but never tore down the websocket session, leaving the socket open and the derived state (connection tracking, worker count, execution status, console output, result caches) populated. Re-entering a workflow then reused the stale session; for the same wid (the wid -> null -> wid pattern) the reconnect guard even short-circuited, the case PR apache#3093's in-canvas guard did not cover.

Tear down every piece of websocket-derived state on workspace destroy: ComputingUnitStatusService.disconnect() (close socket, clear status, stop polling, reset connection tracking and selected unit), WorkflowWebsocketService.closeWebsocket() (reset numWorkers), ExecuteWorkflowService.resetState() (execution state + worker assignments), WorkflowConsoleService.clearConsoleMessages(), and WorkflowResultService.clearResults() (result caches + table-stats ReplaySubject). WorkspaceComponent.ngOnDestroy invokes all of them so re-entering any workflow (same wid included) starts from a clean session.
zyratlo pushed a commit to zyratlo/texera that referenced this pull request Jun 9, 2026
…rd (apache#5565)

### What changes were proposed in this PR?

Websocket-derived front-end state (the connection itself, plus the
execution status, console output, and results built from its events)
lives in singletons outside the workspace. It was never torn down in two
cases, so stale state carried over:

1. **Returning to the dashboard** and re-entering a workflow reused the
previous socket. The connection-tracking fields (`currentConnectedWid` /
`currentConnectedCuid`) also survived, so the reconnect guard saw them
unchanged, skipped reconnecting, and reused the stale socket. (apache#3120 —
the case apache#3093 did not cover.)
2. **Switching computing units** inside the workspace left the previous
unit's console, results, and execution status on screen.

This PR clears that state at both points.

**Workspace exit**: `WorkspaceComponent.ngOnDestroy()` now tears
everything down:

| Call *(new)* | Resets |
| --- | --- |
| `ComputingUnitStatusService.disconnect()` | closes the socket, clears
operator status, stops the unit poll, resets the connection-tracking
fields and the selected unit |
| `ExecuteWorkflowService.resetExecutionAndWorkers()` | execution status
and worker assignments |
| `WorkflowConsoleService.clearConsoleMessages()` | console output |
| `WorkflowResultService.clearResults()` | result caches and table stats
|

**Unit switch**: `ComputingUnitStatusService` emits a reset signal when
it reconnects to a different unit, and `WorkspaceComponent` clears the
same execution / console / result state in response. As a result,
switching units now discards the previous unit's results and console
instead of leaving them on screen.

The remaining websocket-event consumers need no teardown:
`OperatorReuseCacheStatusService` is stateless, and
`udf-debug.service`'s state lives in the `TexeraGraph`, already reset by
`clearWorkflow()`.

### Any related issues, documentation, discussions?

Closes apache#3120. Related: apache#3093 (earlier partial fix for the in-canvas
socket re-open).

### How was this PR tested?

Test with this workflow
[Untitled workflow
(14).json](https://github.com/user-attachments/files/28696700/Untitled.workflow.14.json)


https://github.com/user-attachments/assets/060fe1ac-39cf-45e5-b423-5aa27fe17aed



### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 4.8)

---------

Co-authored-by: Xinyuan Lin <[email protected]>
xuang7 pushed a commit that referenced this pull request Jun 10, 2026
…rd (#5565) [release/v1.2 backport] (#5609)

### What changes were proposed in this PR?

Backport of #5565 ("fix(frontend): clean up websocket state when
returning to the dashboard") to `release/v1.2`.

Applies as a clean `git cherry-pick -x` of the merged squash commit
`ad10b7f2b` — no conflicts and no prerequisite chain (unlike the #5280
backport in #5602). Frontend-only: 14 files changed, 391 insertions, 2
deletions, identical to the original.

For the full change description see #5565. In brief: websocket-derived
front-end state (the connection, plus execution status, console output,
and results built from its events) lives in singletons outside the
workspace and was never torn down when returning to the dashboard or
switching computing units, so stale state carried over. This tears that
state down in `WorkspaceComponent.ngOnDestroy()` and clears it again on
a computing-unit switch.

### Any related issues, documentation, discussions?

Backports #5565 (which closes #3120 on `main`). Related: #3093.

### How was this PR tested?

This is a backport with no changes beyond the single cherry-picked
commit, so it relies on the existing tests carried over from #5565
(added `*.spec.ts` cases across `computing-unit-status`,
`workspace.component`, `execute-workflow`, `workflow-console`,
`workflow-result`, `result-panel`, and `workflow-websocket`).

Backport fidelity was verified locally: after the cherry-pick, every
file touched by #5565 is byte-identical to its state on `main` at the
merged commit (`ad10b7f2b`), and `release/v1.2` had no independent
changes to any of those files.

Full compile and unit-test runs are left to CI.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 4.8)

Co-authored-by: Xinyuan Lin <[email protected]>
ELin2025 pushed a commit to ELin2025/texera that referenced this pull request Jun 16, 2026
…rd (apache#5565)

### What changes were proposed in this PR?

Websocket-derived front-end state (the connection itself, plus the
execution status, console output, and results built from its events)
lives in singletons outside the workspace. It was never torn down in two
cases, so stale state carried over:

1. **Returning to the dashboard** and re-entering a workflow reused the
previous socket. The connection-tracking fields (`currentConnectedWid` /
`currentConnectedCuid`) also survived, so the reconnect guard saw them
unchanged, skipped reconnecting, and reused the stale socket. (apache#3120 —
the case apache#3093 did not cover.)
2. **Switching computing units** inside the workspace left the previous
unit's console, results, and execution status on screen.

This PR clears that state at both points.

**Workspace exit**: `WorkspaceComponent.ngOnDestroy()` now tears
everything down:

| Call *(new)* | Resets |
| --- | --- |
| `ComputingUnitStatusService.disconnect()` | closes the socket, clears
operator status, stops the unit poll, resets the connection-tracking
fields and the selected unit |
| `ExecuteWorkflowService.resetExecutionAndWorkers()` | execution status
and worker assignments |
| `WorkflowConsoleService.clearConsoleMessages()` | console output |
| `WorkflowResultService.clearResults()` | result caches and table stats
|

**Unit switch**: `ComputingUnitStatusService` emits a reset signal when
it reconnects to a different unit, and `WorkspaceComponent` clears the
same execution / console / result state in response. As a result,
switching units now discards the previous unit's results and console
instead of leaving them on screen.

The remaining websocket-event consumers need no teardown:
`OperatorReuseCacheStatusService` is stateless, and
`udf-debug.service`'s state lives in the `TexeraGraph`, already reset by
`clearWorkflow()`.

### Any related issues, documentation, discussions?

Closes apache#3120. Related: apache#3093 (earlier partial fix for the in-canvas
socket re-open).

### How was this PR tested?

Test with this workflow
[Untitled workflow
(14).json](https://github.com/user-attachments/files/28696700/Untitled.workflow.14.json)


https://github.com/user-attachments/assets/060fe1ac-39cf-45e5-b423-5aa27fe17aed



### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 4.8)

---------

Co-authored-by: Xinyuan Lin <[email protected]>
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
)

This PR fixes apache#3085. The issue is caused by a call of
`this.workflowActionService.setWorkflowMetadata(updatedWorkflow);` in
`persistWorkflow`. This call caused the WebSocket service to detect a
workflow metadata update and reopen the WebSocket unnecessarily.
Therefore, the bug can be consistently reproduced by hitting the save
button on the workflow canvas.

This PR introduces a logic check to skip reopening the WebSocket if the
wid remains unchanged, preventing redundant reconnections.
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…rd (apache#5565)

### What changes were proposed in this PR?

Websocket-derived front-end state (the connection itself, plus the
execution status, console output, and results built from its events)
lives in singletons outside the workspace. It was never torn down in two
cases, so stale state carried over:

1. **Returning to the dashboard** and re-entering a workflow reused the
previous socket. The connection-tracking fields (`currentConnectedWid` /
`currentConnectedCuid`) also survived, so the reconnect guard saw them
unchanged, skipped reconnecting, and reused the stale socket. (apache#3120 —
the case apache#3093 did not cover.)
2. **Switching computing units** inside the workspace left the previous
unit's console, results, and execution status on screen.

This PR clears that state at both points.

**Workspace exit**: `WorkspaceComponent.ngOnDestroy()` now tears
everything down:

| Call *(new)* | Resets |
| --- | --- |
| `ComputingUnitStatusService.disconnect()` | closes the socket, clears
operator status, stops the unit poll, resets the connection-tracking
fields and the selected unit |
| `ExecuteWorkflowService.resetExecutionAndWorkers()` | execution status
and worker assignments |
| `WorkflowConsoleService.clearConsoleMessages()` | console output |
| `WorkflowResultService.clearResults()` | result caches and table stats
|

**Unit switch**: `ComputingUnitStatusService` emits a reset signal when
it reconnects to a different unit, and `WorkspaceComponent` clears the
same execution / console / result state in response. As a result,
switching units now discards the previous unit's results and console
instead of leaving them on screen.

The remaining websocket-event consumers need no teardown:
`OperatorReuseCacheStatusService` is stateless, and
`udf-debug.service`'s state lives in the `TexeraGraph`, already reset by
`clearWorkflow()`.

### Any related issues, documentation, discussions?

Closes apache#3120. Related: apache#3093 (earlier partial fix for the in-canvas
socket re-open).

### How was this PR tested?

Test with this workflow
[Untitled workflow
(14).json](https://github.com/user-attachments/files/28696700/Untitled.workflow.14.json)


https://github.com/user-attachments/assets/060fe1ac-39cf-45e5-b423-5aa27fe17aed



### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 4.8)

---------

Co-authored-by: Xinyuan Lin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate console logs

3 participants