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

Race condition is possible on submitting solution to exercise #1696

Open
julian-berbel opened this issue Sep 30, 2021 · 3 comments
Open

Race condition is possible on submitting solution to exercise #1696

julian-berbel opened this issue Sep 30, 2021 · 3 comments

Comments

@julian-berbel
Copy link
Member

We're not sure how, but a user submitted a solution to an exercise twice simultaneously.
This caused two assignments to be created for the same (user + exercise + organization) combination, which caused strange behavior for the user, since the guide progress list would show the exercise as failed, but the results for the exercise would should it as passed (after the solution was fixed by the user).

It seems to me there are two problems mixed here:

  • the guide progress list is not guaranteed to get the same assignment as the exercise view, which is kinda weird,
  • and the race condition itself; ideally it should not be possible to create two assignments for the same (user + exercise + organization) combination.
@julian-berbel
Copy link
Member Author

@flbulgarelli
Copy link
Member

Yup, I agree. However that may introduce a performance hit, since that code is used frequently.

Another solution may be adding a unique constraint in the database for (user_id, organization_id, exercise_id). We might even handle it and find for object again.

@flbulgarelli
Copy link
Member

flbulgarelli commented Oct 4, 2021

🆙 Oh, no, we can not use a transaction there since build just instantiates the object, but it does not persist it, so adding a transaction there will not make it thread-safe @julian-berbel .

We definitely should go for the unique constraint. Error handling should partially go to controller.

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