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

Telegram bridged users that haven't been existed since before Libera.Chat was bridged are not idle-kicked #1460

Open
Mikaela opened this issue Aug 17, 2021 · 3 comments
Labels
matrix.org-support Matrix.org specific problem possibly unrelated to the bridge S-Major Severely degrades major functionality or product features, with no satisfactory workaround T-Defect Bugs, crashes, hangs, vulnerabilities, or other reported problems.

Comments

@Mikaela
Copy link
Contributor

Mikaela commented Aug 17, 2021

Describe the bug

Before I attempted to remedy this situation by hand, I saw these users on #feneas on irc.libera.chat:

2021-W33-3 00:38:53 +0300 -- [#feneas] Telegrambridgeb7 (~teleg_482@2001:470:69fc:105::b78c) H 0 (@telegrambot:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] Akash[m]123 (~teleg_481@2001:470:69fc:105::b74c) H 0 (@telegram_582396714:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] Fla[m] (~teleg_480@2001:470:69fc:105::b70d) H 0 (@telegram_1061398789:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] DaySandBox[m] (~teleg_481@2001:470:69fc:105::b73a) H 0 (@telegram_400753764:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] AmyCupcakesCupca (~teleg_482@2001:470:69fc:105::b756) H 0 (@telegram_59050198:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] ChristerWarn[m] (~teleg_482@2001:470:69fc:105::b76a) H 0 (@telegram_681150630:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] LiaizonWakest[m] (~teleg_481@2001:470:69fc:105::b741) H 0 (@telegram_472917187:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] tulir[m] (~teleg_482@2001:470:69fc:105::b772) H 0 (@telegram_84359547:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] adamadinfinitum[ (~teleg_482@2001:470:69fc:105::b75d) H 0 (@telegram_679079626:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] FeneasMatrixbrid (~teleg_482@2001:470:69fc:105::b777) H 0 (@telegram_852776608:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] ThiagoSkrnio[m] (~teleg_480@2001:470:69fc:105::b712) H 0 (@telegram_109162179:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] TheFuzzStone[m]1 (~teleg_481@2001:470:69fc:105::b728) H 0 (@telegram_253373664:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] IiroLaiho[m] (~teleg_482@2001:470:69fc:105::b784) H 0 (@telegram_962636207:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] Mykhailo[m] (~teleg_481@2001:470:69fc:105::b732) H 0 (@telegram_360450337:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] RickyJones[m] (~teleg_481@2001:470:69fc:105::b71d) H 0 (@telegram_1344516645:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] Zulu[m] (~teleg_481@2001:470:69fc:105::b723) H 0 (@telegram_187150329:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] JasonRobinson[m4 (~teleg_481@2001:470:69fc:105::b718) H 0 (@telegram_123038871:feneas.org)
2021-W33-3 00:38:53 +0300 -- [#feneas] MikaelaTG[m] (~teleg_481@2001:470:69fc:105::b745) H 0 (@telegram_575404822:feneas.org)

The bridge has not been seen since 2020-10-24 so they should neither be sending read-receipts or new messages so I imagine they should be subject to #1194

To Reproduce

Unknown.

Expected behavior

The Telegram users have been kicked the first time libera.chat idle kicker ran since bridging of #feneas.

Screenshots

N/A

Desktop (please complete the following information):

N/A

Smartphone (please complete the following information):

N/A

Additional context

@morguldir
Copy link

It seems that the isUserOnline function in matrix-lastactive returns -1 if it can't figure it out the time since a user was active either through the stored method, presence or by being on the same home server.
https://github.com/Half-Shot/matrix-lastactive/blob/99e2ac9f20e9d3853c04e41e636732aacc6d5a51/src/lib.ts#L127

The last active time in matrix-lastactive is only updated by the bridge when:

Restoring the state from the DB, which is only updated in the other code below:

if (this.activityTracker) {
log.info("Restoring last active times from DB");
const users = await this.dataStore.getLastSeenTimeForUsers();
for (const user of users) {
this.activityTracker.setLastActiveTime(user.user_id, user.ts);
}
log.info(`Restored ${users.length} last active times from DB`);
}

On an Ephemeral Event:

if (userIds) {
for (const userId of userIds) {
this.activityTracker.bumpLastActiveTime(userId);
this.dataStore.updateLastSeenTimeForUser(userId).catch((ex) => {
log.warn(`Failed to bump last active time for ${userId} in database`, ex);
});
}
}

On a normal Event:

if (event.sender && (this.activityTracker ||
this.config.ircService.metrics?.userActivityThresholdHours !== undefined)) {
updatePromise = this.dataStore.updateLastSeenTimeForUser(event.sender);
if (this.activityTracker) {
this.activityTracker.bumpLastActiveTime(event.sender);
}
}

Then these users will be selected as the last to get idle kicked every time, so it would seem that the kick limit just hasn't been high enough for it to kick those users yet. Also possible that it's being excluded by regex in this specific case, or the kicking just fails, but the theory above could still happen elsewhere, and it's probably not reasonable that these users will always be the last ones to be kicked anyway.

@Half-Shot
Copy link
Contributor

Reading the code, it looks like we would be kicking them first? We always run with defaultOnline to false so users we don't have a last active time for are automatically treated as offline. I would have thought given the sort, algorithm, that an activity time of -1 would actually cause them to be selected first.

@morguldir
Copy link

This is the sorting that's used as far as i can tell

const sortedByActiveTime = [...usersToActiveTime.entries()].sort((a, b) => b[1] - a[1]).map(user => user[0]);

Which would put -1 at the end of the list, users that are considered online aren't considered, but since the users in the issue never got kicked by the bridge, I assume the bridge never kicked all the users that were considered offline.

If the bridge ever kicked every offline user though, then it seems like the bug would be avoided, at least for that bridge instance.

@jaller94 jaller94 added T-Defect Bugs, crashes, hangs, vulnerabilities, or other reported problems. S-Major Severely degrades major functionality or product features, with no satisfactory workaround matrix.org-support Matrix.org specific problem possibly unrelated to the bridge labels May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
matrix.org-support Matrix.org specific problem possibly unrelated to the bridge S-Major Severely degrades major functionality or product features, with no satisfactory workaround T-Defect Bugs, crashes, hangs, vulnerabilities, or other reported problems.
Projects
None yet
Development

No branches or pull requests

4 participants