-
Notifications
You must be signed in to change notification settings - Fork 13k
chore: improve the way we send DDP connection data to hooks #38268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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 |
|
WalkthroughThis PR refactors the account session and device login event system by replacing connection-object-based payloads with structured, explicit payload types. Login and logout handlers now emit events with computed metadata (userAgent, clientAddress, instanceId, loginToken) as separate payload fields, and consumers adapt to these new payload shapes while maintaining existing functionality. Changes
Sequence Diagram(s)sequenceDiagram
participant Conn as Connection Event
participant Hook as sauMonitorHooks
participant Emitter as Event Emitters
participant SAUMon as SAUMonitor
participant DevMgmt as Device Management
Conn->>Hook: accounts.login fired
Hook->>Hook: Extract userId, connection
Hook->>Hook: Compute instanceId, userAgent,<br/>clientAddress, host, loginToken
Hook->>Hook: Construct LoginSessionPayload
Hook->>Emitter: emit sau.accounts.login<br/>(LoginSessionPayload)
Hook->>Emitter: emit device-login<br/>(DeviceLoginPayload)
Emitter->>SAUMon: sau.accounts.login received
SAUMon->>SAUMon: _handleSession with payload fields
SAUMon->>SAUMon: Call _getUserAgentInfo(userAgent)
SAUMon->>SAUMon: Build ISession with computed data
Emitter->>DevMgmt: device-login received
DevMgmt->>DevMgmt: Destructure userAgent,<br/>clientAddress, loginToken
DevMgmt->>DevMgmt: Parse userAgent, send notification
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #38268 +/- ##
===========================================
+ Coverage 70.70% 70.76% +0.05%
===========================================
Files 3139 3142 +3
Lines 108744 108920 +176
Branches 19560 19663 +103
===========================================
+ Hits 76887 77072 +185
+ Misses 29856 29841 -15
- Partials 2001 2007 +6
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
77d91f0 to
a4f7f61
Compare
a4f7f61 to
0b0a9a2
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/meteor/server/hooks/sauMonitorHooks.ts (1)
3-50: Replace empty-string loginToken withundefinedto prevent logout failures.When
resumeis missing,loginTokendefaults to'', which gets stored in the Sessions collection during login. During logout, SAUMonitor checksif (!session?.loginToken)(line 148 of SAUMonitor.ts), and the falsy empty string triggers a logout error. SinceLoginSessionPayloadmarksloginTokenas optional, useundefinedinstead.🛠️ Suggested adjustment
- const loginToken = resume ? Accounts._hashLoginToken(resume) : ''; + const loginToken = resume ? Accounts._hashLoginToken(resume) : undefined;
🤖 Fix all issues with AI agents
In `@apps/meteor/server/services/sauMonitor/events.ts`:
- Around line 1-8: The SAU event keys were renamed to namespaced keys but
SAUMonitorClass._handleOnConnection still subscribes to the old
'socket.disconnected' event; update that listener to use the new
'sau.socket.disconnected' key so it matches the sauEvents emitter (reference the
sauEvents Emitter and the _handleOnConnection method in SAUMonitorClass),
ensuring the handler remains registered and sessions are closed correctly.
| import type { ISocketConnection, LoginSessionPayload, LogoutSessionPayload } from '@rocket.chat/core-typings'; | ||
| import { Emitter } from '@rocket.chat/emitter'; | ||
|
|
||
| export const sauEvents = new Emitter<{ | ||
| 'accounts.login': { userId: string; connection: ISocketConnectionLogged }; | ||
| 'accounts.logout': { userId: string; connection: ISocketConnection }; | ||
| 'socket.connected': ISocketConnection; | ||
| 'socket.disconnected': ISocketConnection; | ||
| 'sau.accounts.login': LoginSessionPayload; | ||
| 'sau.accounts.logout': LogoutSessionPayload; | ||
| 'sau.socket.connected': ISocketConnection; | ||
| 'sau.socket.disconnected': ISocketConnection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update remaining listeners to sau.socket.disconnected.
Event keys changed here, but SAUMonitorClass._handleOnConnection still listens to socket.disconnected (Line 99 in apps/meteor/app/statistics/server/lib/SAUMonitor.ts). That listener will stop firing, leaving sessions open.
🔧 Suggested fix
- sauEvents.on('socket.disconnected', async ({ id, instanceId }) => {
+ sauEvents.on('sau.socket.disconnected', async ({ id, instanceId }) => {🤖 Prompt for AI Agents
In `@apps/meteor/server/services/sauMonitor/events.ts` around lines 1 - 8, The SAU
event keys were renamed to namespaced keys but
SAUMonitorClass._handleOnConnection still subscribes to the old
'socket.disconnected' event; update that listener to use the new
'sau.socket.disconnected' key so it matches the sauEvents emitter (reference the
sauEvents Emitter and the _handleOnConnection method in SAUMonitorClass),
ensuring the handler remains registered and sessions are closed correctly.
Proposed changes (including videos or screenshots)
After some investigation, context gathering, and a discussion with Diego Sampaio, we aligned on the scope of this task.
The goal is to improve how DDP connection headers are handled in sauMonitorHooks.ts.
While the broader issue involves multiple places where the full connection object is passed downstream instead of only the required data, addressing all of those cases is outside the scope of this task.
To make the change safer and more explicit, I will introduce dedicated types for the event payloads instead of passing the entire connection object.
Issue(s)
Steps to test or reproduce
Further comments
Doubt:
Are the new types (DeviceLoginPayload, LoginSessionPayload, LogoutSessionPayload) and the util function (getHeader) properly located in the directory tree?
Summary by CodeRabbit
Refactor
Chores
✏️ Tip: You can customize this high-level summary in your review settings.