feat: ddp-client connection liveness check and forceReopen#41353
feat: ddp-client connection liveness check and forceReopen#41353Rohit3523 wants to merge 5 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📜 Recent review details⏰ Context from checks skipped due to timeout. (4)
WalkthroughThe DDP client adds ping/pong liveness probing, deduplicated reopening, safer socket closure, public recovery APIs, and tests for alive, dead, and disconnected states. ChangesDDP liveness recovery
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant Connection
participant WebSocket
Caller->>Connection: checkAndReopen()
Connection->>WebSocket: send DDP ping
WebSocket-->>Connection: pong or timeout
Connection->>Connection: forceReopen when unavailable
Connection-->>Caller: return recovery result
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
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 |
🦋 Changeset detectedLatest commit: 42824ef The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #41353 +/- ##
===========================================
- Coverage 69.12% 68.69% -0.44%
===========================================
Files 3762 4139 +377
Lines 147936 159173 +11237
Branches 26428 28123 +1695
===========================================
+ Hits 102261 109342 +7081
- Misses 41185 44683 +3498
- Partials 4490 5148 +658
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@packages/ddp-client/__tests__/Connection.spec.ts`:
- Around line 371-375: Wrap the fake-timer setup, probe execution, timer
advancement, and assertion in a try/finally block within the relevant Connection
test, and move jest.useRealTimers() into finally so timers are restored even
when the assertion fails.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7ad664a3-00a4-41d0-8187-b0c2a548e7bf
📒 Files selected for processing (2)
packages/ddp-client/__tests__/Connection.spec.tspackages/ddp-client/src/Connection.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/ddp-client/src/Connection.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Hacktron Security Check
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
packages/ddp-client/__tests__/Connection.spec.ts
**/*.spec.ts
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.spec.ts: Use descriptive test names that clearly communicate expected behavior in Playwright tests
Use.spec.tsextension for test files (e.g.,login.spec.ts)
Files:
packages/ddp-client/__tests__/Connection.spec.ts
🧠 Learnings (5)
📚 Learning: 2026-02-24T19:22:48.358Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/omnichannel/omnichannel-send-pdf-transcript.spec.ts:66-67
Timestamp: 2026-02-24T19:22:48.358Z
Learning: In Playwright end-to-end tests (e.g., under apps/meteor/tests/e2e/...), prefer locating elements by translated text (getByText) and ARIA roles (getByRole) over data-qa attributes. If translation values change, update the corresponding test locators accordingly. Never use data-qa locators. This guideline applies to all Playwright e2e test specs in the repository and helps keep tests robust to UI text changes and accessible semantics.
Applied to files:
packages/ddp-client/__tests__/Connection.spec.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
packages/ddp-client/__tests__/Connection.spec.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
packages/ddp-client/__tests__/Connection.spec.ts
📚 Learning: 2026-03-06T18:10:15.268Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:15.268Z
Learning: In tests (especially those using testing-library/dom/jsdom) for Rocket.Chat components, the HTML <code> element has an implicit ARIA role of 'code'. Therefore, screen.getByRole('code') or screen.findByRole('code') will locate <code> elements even without a role attribute. Do not flag findByRole('code') as invalid in reviews; prefer using the implicit role instead of adding role="code" unless necessary for accessibility.
Applied to files:
packages/ddp-client/__tests__/Connection.spec.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
packages/ddp-client/__tests__/Connection.spec.ts
🔇 Additional comments (1)
packages/ddp-client/__tests__/Connection.spec.ts (1)
337-363: LGTM!Also applies to: 378-459
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Why this is needed
On mobile, a WebSocket can become a zombie: the client still reports
status === 'connected', but the underlying TCP transport is already dead. Common causes:onclose, so the client has no signal that anything is wrong.Symptom: the app looks connected, but method calls and subscriptions silently hang or fail, and the user only recovers by force-killing the app. The existing client only learns about death via
oncloseor the server's own ping timeout — neither is reliable when the drop is silent on the client side.DDP already has
ping/pong, but it's normally server-initiated (server pings, client answers). This PR adds a client-initiated liveness probe so the client can detect a dead path itself and recover autonomously.Proposed changes
Connection.probe(timeoutMs?)— sends a DDPpingand resolvestrueif apongarrives withintimeoutMs.Connection.forceReopen()— closes + reconnects, deduplicating concurrent callers via a shared in-flight promise.Connection.checkAndReopen(probeTimeoutMs?)— probes whenconnected; force-reopens when not connected or on a dead probe. Also exposed onDDPSDK(sdk.checkAndReopen()).Connection.close()now severs socket handlers before closing so a dying socket can't deliver late messages or fireoncloseon the live connection.Steps to test or reproduce
await sdk.checkAndReopen()returnstruewhen the socket is healthy, and recovers when the transport is dead.onclose, no traffic) is detected by thepongtimeout and force-reopened.Further comments
The methods are inert until something calls
checkAndReopen()— e.g. on app foreground or aNetInfoconnectivity change in the mobile app. That trigger wiring lives in the mobile repo and is intentionally out of scope here; this PR only provides the capability and makes it reachable on the publicDDPSDK.https://rocketchat.atlassian.net/browse/CORE-2282
Summary by CodeRabbit