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

Received two requests from the same user at the same time #81

Closed
jacob-g opened this issue Oct 22, 2020 · 0 comments · Fixed by #82
Closed

Received two requests from the same user at the same time #81

jacob-g opened this issue Oct 22, 2020 · 0 comments · Fixed by #82
Assignees
Labels
bug Something isn't working

Comments

@jacob-g
Copy link
Member

jacob-g commented Oct 22, 2020

The extension normally should prohibit this. They most likely hit the submit button twice, but this means we have a race condition. Specifically, the following:

hasBeenSubmitted <- does user have active request?
(intermediate logic)
if hasBeenSubmitted then show error that user has already submitted request
else store request

The race condition is between the two. Ideally this should be done as a transaction to avoid this problem. This may require some significant refactoring since currently the way this is designed, each database operation is designed to be atomic. The way I am thinking to do this is make the database driver an argument to each of the database interaction functions (ones that do writes will require a writeable database instance). Then we can create a function for starting and committing a transaction. So it would be something like this:

db <- get writeable database and begin transaction
hasBeenSubmitted <- does user have active request? (determine using db)
(intermediate logic)
if hasBeenSubmitted then show error that user has already been submitted request
else store request (using db)
commit transaction for db
release db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant