cbeer / devise-guests

fake 'em until you make 'em
MIT License
130 stars 31 forks source link

Fix race condition with multi-thread servers with guest accounts when logging into existing account #45

Closed joeyparis closed 11 months ago

joeyparis commented 2 years ago

When logging into an existing account from a guest account on a multi-thread server (like Puma) devise-guests enters a race condition where some threads believe the guest user exists and some threads believe the guest user has been deleted and then tries to create it again. This leads to an effectively meaningless error that the guest user's email is already taken in the database as the non-guest account is logged in. This solution adds a dependency for with_advisory_lock but it prevents the unnecessary error.

We should probably also make sure this doesn't "undelete" deleted guest account on successful login.

pacso commented 1 year ago

Can you explain how the race condition occurs? I wonder if there might be another solution rather than introducing an additional dependency.

pacso commented 11 months ago

Closing, since I cannot reproduce and no valid tests were provided.