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

Concurrency issues when entering trials #617

Open
wheeyls opened this issue May 10, 2020 · 1 comment
Open

Concurrency issues when entering trials #617

wheeyls opened this issue May 10, 2020 · 1 comment
Assignees

Comments

@wheeyls
Copy link

wheeyls commented May 10, 2020

The "choose trial" logic is not atomic, so it is easy to run it multiple times for the same user.

Specifically, there is a read here:

self.alternative = @user[@experiment.key]

With a matching write here:

@user[@experiment.key] = alternative.name if !@experiment.has_winner? && should_store_alternative?

With no lock around these reads and writes, it is very easy to get into a situation where this code runs simultaneously on different processes, and puts the user in a strange state.

When using cookies, I don't think there is a solution for this that will be stable. But when using Redis for persistence, it should be possible to be consistent in a concurrent environment.

Honestly after looking into this, I'm not sure that is a problem worth solving for my use case. That's why this is an issue and not a PR, just wanted to capture this problem so it can be discussed.

@andrehjr
Copy link
Member

Hey @wheeyls, thanks for bringing this up.

Indeed, mixing concurrency/writes/reads without some kind of locks may lead to inconsistency.

Probably most users of Split are using Redis as a default for persistence, but as it's possible to create custom adapters too. So we'd need a way to not couple the solution with Redis or any other database. But still, be able to implement a lock mechanism.

In the meantime I'm planning a refactor around Split::Trial, maybe I can think of something on the way.

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

No branches or pull requests

2 participants