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

Avoid DB race condition when activating #1072

Merged
merged 3 commits into from
Aug 7, 2023

Conversation

michael-markl
Copy link
Member

To avoid race conditions when activating a card (e.g. if the app somehow requests activation too often), this PR introduces DB transaction isolation for the activation transaction.

Copy link
Contributor

@sarahsporck sarahsporck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is hard to actually test. But normal activation still works as intended.

Copy link
Contributor

@f1sh1918 f1sh1918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine to me

@michael-markl
Copy link
Member Author

I actually tested this by adding some thread sleeping inside the transaction and activated twice the same card.
That threw an error (as expected) for the second attempt. Without the change it didn't throw the error.

@michael-markl
Copy link
Member Author

I might test this once more to check if it also throws if we activate different cards at the same time. That should hopefully not be the case (but I'll check it once more)

# Conflicts:
#	backend/src/main/kotlin/app/ehrenamtskarte/backend/verification/webservice/schema/CardMutationService.kt
@michael-markl
Copy link
Member Author

I confirmed that activating different in parallel cards does not error out.

@michael-markl michael-markl enabled auto-merge August 7, 2023 18:53
@michael-markl michael-markl merged commit 109e6db into main Aug 7, 2023
@michael-markl michael-markl deleted the avoid-race-condition-when-activating branch August 7, 2023 19:08
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

Successfully merging this pull request may close these issues.

3 participants