Skip to content
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

fix: Presence broadcast isn't enabled after license validation #30282

Merged
merged 16 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tall-pumpkins-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/presence": patch
---

Fixed presence broadcast being disabled on server restart
11 changes: 8 additions & 3 deletions ee/packages/presence/src/Presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Presence extends ServiceClass implements IPresence {

private broadcastEnabled = true;

private hasLicense = false;
private hasLicense?: boolean = undefined;

private lostConTimeout?: NodeJS.Timeout;

Expand Down Expand Up @@ -74,7 +74,7 @@ export class Presence extends ServiceClass implements IPresence {
}

async toggleBroadcast(enabled: boolean): Promise<void> {
if (!this.hasLicense && this.getTotalConnections() > MAX_CONNECTIONS) {
if (this.hasLicense === false && this.getTotalConnections() > MAX_CONNECTIONS) {
throw new Error('Cannot enable broadcast when there are more than 200 connections');
}
this.broadcastEnabled = enabled;
Expand Down Expand Up @@ -232,14 +232,19 @@ export class Presence extends ServiceClass implements IPresence {
}

private async validateAvailability(): Promise<void> {
if (this.hasLicense) {
if (this.hasLicense !== false) {
return;
}

if (this.getTotalConnections() > MAX_CONNECTIONS) {
this.broadcastEnabled = false;

await Settings.updateValueById('Presence_broadcast_disabled', true);
} else {
const presenceBroadcastDisabled = await Settings.findOneById('Troubleshoot_Disable_Presence_Broadcast');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks expensive, doesn't it? potentially two trips for every new connection?

Copy link
Member Author

@matheusbsilva137 matheusbsilva137 Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it did 😬
I've just had a better idea, I'm now checking the broadcastEnabled property to make sure that presence broadcast is always enabled when there's a valid license (so we just do it once, not at every new connection).

if (presenceBroadcastDisabled) {
await this.toggleBroadcast(!presenceBroadcastDisabled.value);
}
}
}

Expand Down