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 a race when registering via email 3pid #16827

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

MatMaul
Copy link
Contributor

@MatMaul MatMaul commented Jan 18, 2024

When hitting the race, 2 different users are created for an unique 3pid email.

Performance impact should be fairly minimal since we usually don't register a new user 10 times per second, unlike sending messages.

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct
    (run the linters)

@CLAassistant
Copy link

CLAassistant commented Jan 18, 2024

CLA assistant check
All committers have signed the CLA.

@@ -506,6 +509,23 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
"An access token should not be provided on requests to /register (except if type is m.login.application_service)",
)

# Take a global lock when doing user registration to avoid races,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am only protecting normal user registration with the lock because I think _do_appservice_registration and _do_guest_registration are safe but I am not sure to be honest, especially for the appservice one.

Out of safety we may protect the whole code in on_POST, opinions welcome.

@MatMaul MatMaul force-pushed the register-email-3pid-race branch 3 times, most recently from c2cfa8b to ea74288 Compare January 22, 2024 00:26
@MatMaul
Copy link
Contributor Author

MatMaul commented Jan 22, 2024

Failing tests should turn to green once #16840 is merged.

erikjohnston pushed a commit that referenced this pull request Mar 14, 2024
When a lot of locks are waiting for a single lock, notifying all locks
independently with `call_later` on each release is really costly and
incurs some kind of async contention, where the CPU is spinning a lot
for not much.

The included test is taking around 30s before the change, and 0.5s
after.

It was found following failing tests with
#16827.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants