Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix leaking per-room profiles for local users when rebuilding directory #10761

Conversation

DMRobertson
Copy link
Contributor

@DMRobertson DMRobertson commented Sep 4, 2021

Another step to tackle #5677.

I think this series of changes should ensure that rebuilding the user directory doesn't leak per-room profiles for local users. To convince myself of this I added some extra test cases.

I also took the opportunity to try and apply some extra cleanups.

David Robertson added 9 commits September 3, 2021 20:09
- Distinguish between tests of the incremental updates (handler) versus
  the initial background process (storage)
- Add test cases to futher probe that initial background process
- Add test case to check that reactivated users are added back to the directory
I don't fully understand why this was needed, but without this I was
missing entries from the users table that upcoming changes are about to
expect. (Was getting failures to select from the users table because
there were missing rows.)
can't see how to correctly configure the homeserver, so let's hack it
@DMRobertson DMRobertson changed the title Dmr/user directory nickname leaks 2 Fix leaking per-room profiles for local users when rebuilding directory Sep 6, 2021
@DMRobertson DMRobertson requested review from reivilibre and a team September 6, 2021 14:04
@DMRobertson DMRobertson marked this pull request as ready for review September 6, 2021 14:04
@reivilibre reivilibre self-assigned this Sep 7, 2021
Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

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

Looking good. I notice the tests still have a few TODOs, is that for now or another PR?

docs/user_directory.md Outdated Show resolved Hide resolved
synapse/storage/databases/main/user_directory.py Outdated Show resolved Hide resolved
Comment on lines +547 to +549
UserDirectoryBackgroundUpdateStore,
ApplicationServiceWorkerStore,
RegistrationWorkerStore,
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did this come from/Can you explain? (sounds sarcastic — it's not. I just wonder if this is what we're meant to do. I guess the store is one of those big mixins we were talking about [finally clicked in my head]. I don't know enough about Python multi-inheritance rules — do we do this anywhere else? Will it cause problems?)

Copy link
Contributor Author

@DMRobertson DMRobertson Sep 7, 2021

Choose a reason for hiding this comment

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

I guess the store is one of those big mixins we were talking about [finally clicked in my head].

DataStore is a class with a lot of parents; dunno if we'd consider that a mixin. (I think of a mixin as something that's designed to be used with multiple inheritance, but isn't really a standalone Thing/Entity by itself.)

But yeah, the DataStore inherits from 9001 other Stores but... they're not all independent. Sometimes they call each other's methods.

Being honest, my motivation is

I just wonder if this is what we're meant to do.

erm, pass. I think the status quo is "yeah it sucks, and @erikjohnston has a plan how we could do things better one day"

I don't know enough about Python multi-inheritance rules — do we do this anywhere else? Will it cause problems?)

I had to be careful to order the parent classes, or else Python will fail to create a class because it can't build a consistent MRO.

Will it cause problems?

Was hoping to rely on unit tests to figure that out. Would appreciate input from the rest of the team here.

Having looked over it, I think this these classes get pulled in by the UserDirectoryBackgroundUpdateStore, not the UserDirectoryStore.

tests/storage/test_user_directory.py Show resolved Hide resolved
as_user = "@as_user_potato:test"
self.get_success(self.store.register_user(user_id=as_user, password_hash=None))

# TODO can we configure the app service up front somehow? This is a hack.
Copy link
Contributor

Choose a reason for hiding this comment

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

would have thought it should be doable. There are @override_config annotations for the standard config, but not sure what the equivalent is for appservices...

Looks like you have to create files and configure those, see (& copy?) ApplicationServiceStoreTestCase.setUp...

tests/storage/test_user_directory.py Show resolved Hide resolved
@reivilibre reivilibre removed their assignment Sep 7, 2021
@DMRobertson
Copy link
Contributor Author

A lot of test failures. I wonder if this is the result of me messing about with those inheritance hierarchies? I'll investigate

@DMRobertson DMRobertson force-pushed the dmr/user-directory-nickname-leaks-2 branch from a54460e to cfe7458 Compare September 8, 2021 14:55
@DMRobertson
Copy link
Contributor Author

A lot of test failures. I wonder if this is the result of me messing about with those inheritance hierarchies? I'll investigate

It was down to that change. I found it easiest to reset, manually apply the typing and lint fixes, then force push (sorry).

@reivilibre
Copy link
Contributor

the SyTests using workers seem deeply sad, probably worth fixing before I pass a review

@reivilibre reivilibre removed their request for review September 8, 2021 15:34
@DMRobertson
Copy link
Contributor Author

I think I've seen that set of failures before, see e.g. https://buildkite.com/matrix-dot-org/sytest/builds/1589 (from a completely different branch with no synapse changes). That's a bit suspicious!

@DMRobertson
Copy link
Contributor Author

I think I need 40a1fdd to get the with-workers tests passing. To proceed, I think it's probably easiest(?) to get #10695 merged into develop first, then merge in develop to this branch.

@DMRobertson
Copy link
Contributor Author

Going to close this and chop up into lots of smaller PRs to make it easier to follow.

@DMRobertson DMRobertson closed this Sep 9, 2021
@DMRobertson DMRobertson deleted the dmr/user-directory-nickname-leaks-2 branch October 8, 2021 14:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants