Close WebSocket cleanly before domain reload - #1287
Conversation
📝 WalkthroughWalkthrough
ChangesWebSocket domain-reload shutdown
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ForceStop
participant CloseForDomainReload
participant WebSocket
ForceStop->>CloseForDomainReload: request bounded close
CloseForDomainReload->>WebSocket: send EndpointUnavailable output
CloseForDomainReload->>WebSocket: abort on failure or timeout
ForceStop->>WebSocket: dispose socket resources
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
68f1c84 to
5d4e473
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Services/WebSocketTransportClientTests.cs (1)
88-144: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd terminal-state regressions.
Add
ClosedandAbortedcases asserting that neitherCloseOutputAsyncnorAbortis called. Those branches are part of the stated shutdown contract but are not covered here.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@TestProjects/UnityMCPTests/Assets/Tests/EditMode/Services/WebSocketTransportClientTests.cs` around lines 88 - 144, Add terminal-state regression tests alongside the existing CloseForDomainReload tests using RecordingWebSocket configured with WebSocketState.Closed and WebSocketState.Aborted. Assert that both CloseOutputCalled and AbortCalled remain false in each case, preserving the existing ConnectingSocket test pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs`:
- Around line 181-183: Update CloseForDomainReload to attempt acquiring
_sendLock without blocking before calling CloseOutputAsync; perform the
domain-reload close only when the lock is acquired, release it afterward, and
abort immediately when a normal SendJsonAsync already holds or is queued for the
lock.
---
Nitpick comments:
In
`@TestProjects/UnityMCPTests/Assets/Tests/EditMode/Services/WebSocketTransportClientTests.cs`:
- Around line 88-144: Add terminal-state regression tests alongside the existing
CloseForDomainReload tests using RecordingWebSocket configured with
WebSocketState.Closed and WebSocketState.Aborted. Assert that both
CloseOutputCalled and AbortCalled remain false in each case, preserving the
existing ConnectingSocket test pattern.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 725ad9b5-aabf-4694-b456-5404fb86fea1
📒 Files selected for processing (2)
MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.csTestProjects/UnityMCPTests/Assets/Tests/EditMode/Services/WebSocketTransportClientTests.cs
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d4e4731dd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
5d4e473 to
e6d8fc0
Compare
Description
Replace immediate WebSocket abort during Unity domain reload with a bounded close-output attempt that is serialized against normal sends and falls back to abort without blocking the Editor.
Type of Change
Changes Made
EndpointUnavailableclose output forOpenandCloseReceivedsockets with a 100 ms budget.ConnectingandCloseSent.ClosedandAbortedsockets untouched.Compatibility / Package Source
#beta,#main, tag, branch, orfile:): branch derived directly from officialbeta(bd72241ab91c664176091789c9408d676783abec); localfile:source for validation onlyPackages/packages-lock.json(if using a Git package URL): N/AThe 100 ms close budget is bounded; all failure paths retain the previous abort behavior.
Testing/Screenshots/Recordings
cd Server && uv run pytest tests/ -v)Unity 2022.3.62f3 targeted reload suite: 21 passed, 0 failed. Tests cover close output,
CloseReceived, timeout, exception, unfinished states, and terminal states; the send-lock serialization path is compiled and source-reviewed.Documentation Updates
tools/UPDATE_DOCS_PROMPT.md(recommended)Related Issues
Relates to #1207.
Additional Notes
A rebuilt stable branch containing this PR plus #1285 and #1286 passed 162 targeted EditMode tests: 161 passed, 0 failed, 1 intentional stress-only skip.
git diff --checkpasses.