Skip to content

fix: LiveQuery subscriptions leak when a client reuses a subscribe requestId#10499

Merged
mtrezza merged 2 commits into
parse-community:alphafrom
mtrezza:fix/livequery-duplicate-requestid-leak
Jun 10, 2026
Merged

fix: LiveQuery subscriptions leak when a client reuses a subscribe requestId#10499
mtrezza merged 2 commits into
parse-community:alphafrom
mtrezza:fix/livequery-duplicate-requestid-leak

Conversation

@mtrezza

@mtrezza mtrezza commented Jun 10, 2026

Copy link
Copy Markdown
Member

Issue

Parse Server LiveQuery accepts multiple subscribe frames from the same WebSocket client that reuse a single requestId. The client-side subscription metadata is keyed only by requestId, so each duplicate subscribe overwrites the previous entry while the previously created subscription remains in the server-wide subscriptions map. Disconnect cleanup only walks the surviving client metadata, so the orphaned subscriptions are never removed — they persist for the lifetime of the process, consume memory, and are evaluated on every subsequent object event for the affected class.

Tasks

  • Add tests

Summary by CodeRabbit

  • Bug Fixes

    • Fixed LiveQuery subscription cleanup when clients reuse request IDs with different queries, preventing orphaned subscriptions from persisting on the server.
    • Ensured subscriptions are properly replaced rather than duplicated when the same request ID is reused.
  • Tests

    • Added comprehensive test suite validating subscription lifecycle behavior for duplicate request ID scenarios.

@parse-github-assistant

Copy link
Copy Markdown

🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review.

Tip

  • Keep pull requests small. Large PRs will be rejected. Break complex features into smaller, incremental PRs.
  • Use Test Driven Development. Write failing tests before implementing functionality. Ensure tests pass.
  • Group code into logical blocks. Add a short comment before each block to explain its purpose.
  • We offer conceptual guidance. Coding is up to you. PRs must be merge-ready for human review.
  • Our review focuses on concept, not quality. PRs with code issues will be rejected. Use an AI agent.
  • Human review time is precious. Avoid review ping-pong. Inspect and test your AI-generated code.

Note

Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect.

Caution

Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 096063fc-50f2-49b6-9100-51fe7f0a6ec6

📥 Commits

Reviewing files that changed from the base of the PR and between c700ebd and 24ce5f9.

📒 Files selected for processing (4)
  • spec/ParseLiveQuery.spec.js
  • spec/helper.js
  • src/LiveQuery/ParseLiveQueryServer.ts
  • src/LiveQuery/Subscription.js

📝 Walkthrough

Walkthrough

This PR fixes LiveQuery subscription leaks when clients reuse requestIds. It deduplicates requestId registrations in Subscription, guards server-side cleanup in ParseLiveQueryServer during disconnect/subscribe/unsubscribe phases, fixes mock caching in the test harness, and adds comprehensive end-to-end tests validating subscription replacement and event delivery isolation.

Changes

LiveQuery duplicate requestId handling

Layer / File(s) Summary
Subscription requestId deduplication
src/LiveQuery/Subscription.js
addClientSubscription checks for existing requestId before registering, preventing duplicate (clientId, requestId) entries that complicate cleanup.
Server-side lifecycle cleanup guards
src/LiveQuery/ParseLiveQueryServer.ts
Disconnect, subscribe (with prior-subscription teardown), and unsubscribe paths now conditionally guard access to per-class subscription maps, removing orphaned class/subscription entries only when no clients remain.
Test harness mock-caching fix
spec/helper.js
jasmine.mockLibrary now caches the original export only once per library, preventing re-mocks from overwriting the stored original and breaking jasmine.restoreLibrary restoration across test runs.
LiveQuery duplicate requestId test suite
spec/ParseLiveQuery.spec.js
New suite with raw WebSocket clients validates subscription replacement, multi-client isolation, event delivery divergence, and post-cleanup update operations when requestIds are reused across queries, classes, and disconnects.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • parse-community/parse-server#10414: Both PRs update ParseLiveQueryServer's disconnect-side cleanup of subscription/class maps, with the retrieved PR adding a disconnect test verifying cleanup behavior.
  • parse-community/parse-server#10133: Both PRs modify _handleSubscribe in src/LiveQuery/ParseLiveQueryServer.ts—the main PR changes subscription replacement for duplicate requestIds, while the other adds CLP gating at subscribe time.
🚥 Pre-merge checks | ✅ 7
✅ Passed checks (7 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly summarizes the main fix: preventing LiveQuery subscriptions from leaking when clients reuse requestIds.
Description check ✅ Passed The PR description includes an Issue section describing the problem and a Tasks section showing tests were added, but lacks an Approach section explaining the implementation changes.
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.
Security Check ✅ Passed No security vulnerabilities found. PR fixes LiveQuery subscription leaks while maintaining proper authorization boundaries and client isolation. All code paths are safely guarded.
Engage In Review Feedback ✅ Passed PR has no substantive review feedback comments to engage with - only auto-generated CodeRabbit bot notifications about triggering a review. The check is not applicable to newly submitted PRs withou...

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.22.0)

OpenGrep fatal error (exit code 2): [00.13][ERROR]: Error: exception Unix_error: No such file or directory stat spec/ParseLiveQuery.spec.js
Raised by primitive operation at UTmp.replace_named_pipe_by_regular_file_if_needed in file "libs/commons/UTmp.ml", line 145, characters 8-27
Called from Scan_CLI.replace_target_roots_by_regular_files_where_needed.(fun) in file "src/osemgrep/cli_scan/Scan_CLI.ml", lines 1086-1087, characters 19-65
Called from List_.fast_map in file "libs/commons/List_.ml", line 81, characters 17-20
Called from


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.

@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.60%. Comparing base (f12e1c3) to head (24ce5f9).
⚠️ Report is 1 commits behind head on alpha.

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha   #10499      +/-   ##
==========================================
+ Coverage   92.59%   92.60%   +0.01%     
==========================================
  Files         193      193              
  Lines       16928    16941      +13     
  Branches      234      240       +6     
==========================================
+ Hits        15674    15689      +15     
+ Misses       1231     1229       -2     
  Partials       23       23              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mtrezza

mtrezza commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mtrezza mtrezza merged commit 3fad4fb into parse-community:alpha Jun 10, 2026
39 of 40 checks passed
parseplatformorg pushed a commit that referenced this pull request Jun 10, 2026
## [9.9.1-alpha.8](9.9.1-alpha.7...9.9.1-alpha.8) (2026-06-10)

### Bug Fixes

* LiveQuery subscriptions leak when a client reuses a subscribe requestId ([#10499](#10499)) ([3fad4fb](3fad4fb))
@mtrezza mtrezza deleted the fix/livequery-duplicate-requestid-leak branch June 10, 2026 23:49
@parseplatformorg

Copy link
Copy Markdown
Contributor

🎉 This change has been released in version 9.9.1-alpha.8

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:released-alpha Released as alpha version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants