Skip to content

fix(ws): remove all frame listeners on client closure#2739

Merged
kettanaito merged 2 commits into
mainfrom
fix/ws-listener-cleanup
May 7, 2026
Merged

fix(ws): remove all frame listeners on client closure#2739
kettanaito merged 2 commits into
mainfrom
fix/ws-listener-cleanup

Conversation

@kettanaito
Copy link
Copy Markdown
Member

Makes sure that WebSocket frames also remove all their listeners on connection closure.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ea15cdcd-8d72-4c41-a163-14a6f9ad7045

📥 Commits

Reviewing files that changed from the base of the PR and between d697485 and a351553.

📒 Files selected for processing (1)
  • src/core/experimental/sources/interceptor-source.ts

📝 Walkthrough

Walkthrough

The PR adds resource cleanup logic to the WebSocket interceptor source. When a WebSocket client connection closes, the frame now removes all its registered event listeners, preventing listener leakage after disconnection. This mirrors existing cleanup behavior in the HTTP response handler.

Changes

WebSocket Connection Cleanup

Layer / File(s) Summary
WebSocket Cleanup Implementation
src/core/experimental/sources/interceptor-source.ts
Registers a one-time close listener on the WebSocket client to call removeAllListeners() when the client disconnects, preventing orphaned event listeners.

Possibly Related PRs

  • mswjs/msw#2737: Related cleanup work in the same file—both PRs ensure frame event listeners are removed to prevent listener retention, with this PR adding WebSocket connection close cleanup.

Estimated Code Review Effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 When sockets close their sleepy eyes,
The listeners fade away and rise—
No lingering ghosts of events past,
Just cleanup magic, clean and fast!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding cleanup of frame listeners when WebSocket clients disconnect, which matches the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining that WebSocket frames now remove listeners on connection closure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ws-listener-cleanup

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 7, 2026

Open in StackBlitz

npm i https://pkg.pr.new/msw@2739

commit: af2dac4

@kettanaito kettanaito merged commit 91a5d41 into main May 7, 2026
31 of 32 checks passed
@kettanaito kettanaito deleted the fix/ws-listener-cleanup branch May 7, 2026 13:36
@kettanaito
Copy link
Copy Markdown
Member Author

Released: v2.14.5 🎉

This has been released in v2.14.5.

Get these changes by running the following command:

npm i msw@latest

Predictable release automation by Release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant