mumuki / mumuki-laboratory

:microscope: Where students practice and receive automated and human feedback

Home Page:http://mumuki.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Race condition is possible on submitting solution to exercise

julian-berbel opened this issue · comments

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.

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.

🆙 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.