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

fix: adding the pg_lock for the token #293

Merged
merged 2 commits into from
Dec 13, 2023

Conversation

geekbrother
Copy link
Contributor

@geekbrother geekbrother commented Dec 13, 2023

Description

This PR adds an additional pg_advisory_xact_lock based on the device token to prevent data race when concurrent client creations occur with the same token id and different client IDs, because at the moment only the client ID is used for the lock. In such cases, we have an unique constraint violation error for the device token because we have a parallel insert.

The pg_advisory_xact_locks are released at the end of the transaction.

Resolves #292

How Has This Been Tested?

Current functional database tests.

Due Diligence

  • Breaking change
  • Requires a documentation update
  • Requires a e2e/integration test update

@geekbrother geekbrother self-assigned this Dec 13, 2023
@arein arein added the accepted The issue has been accepted into the project label Dec 13, 2023
@geekbrother geekbrother marked this pull request as ready for review December 13, 2023 11:58
Copy link
Member

@chris13524 chris13524 left a comment

Choose a reason for hiding this comment

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

LGMT. Can we do both of these in the same statement to save RTT?

@geekbrother
Copy link
Contributor Author

LGMT. Can we do both of these in the same statement to save RTT?

Good catch! Yes, we can do SELECT pg_lock.., pg_lock;. Tested it in the local Postgres, and it works as expected.

@geekbrother geekbrother merged commit d77fa50 into main Dec 13, 2023
6 checks passed
@geekbrother geekbrother deleted the max/chore/add_lock_for_tokenif branch December 13, 2023 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue has been accepted into the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix: concurrent client creation with the same token and different client id
3 participants