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 handlng of concurrent inserts of the 2FA provider registry DAO #10943

Merged
merged 1 commit into from
Aug 31, 2018

Conversation

ChristophWurst
Copy link
Member

This was discovered by Sentry once on my private instance and so far I have not been able to reproduce this. Still, the way I implemented this before is prone to concurrency issues.

The problem originates from

private function fixMissingProviderStates(array $providerStates,
. In this method, we attempt to insert entries for all providers that weren't known before. So if two or more requests concurrently hit section
$providerStates = $this->providerRegistry->getProviderStates($user);
$providers = $this->providerLoader->getProviders($user);
$fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user);
, they all try to persist the provider state.

I was unable to reproduce this with benchmarking tools and high numbers of concurrent requests, so I used the debugger to simulate it.

Steps to reproduce:

  • Delete the backup codes entry in the oc_twofactor_providers table of your test user
  • Set breakpoint at
    $fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user);
  • Wait for your IDE to stop the php execution
  • Re-insert the backup codes line deleted above
  • Continue php execution

Before this patch: 💥

With this patch: exception is caught and update is run instead.

cc @rullzer @MorrisJobke as discussed at the conf.

@MorrisJobke MorrisJobke mentioned this pull request Aug 31, 2018
6 tasks
@ChristophWurst
Copy link
Member Author

Steps to reproduce:

Edit: to reproduce the issue with the old code, you actually have to set the break point at

and insert the row at that point.

@MorrisJobke MorrisJobke merged commit 7159ac1 into master Aug 31, 2018
@MorrisJobke MorrisJobke deleted the fix/2fa-provider-dao-concurrent-insert branch August 31, 2018 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants