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

Potential SELECT/INSERT Race Condition in Batch Creation API #620

Open
jkva opened this issue Feb 16, 2022 · 0 comments
Open

Potential SELECT/INSERT Race Condition in Batch Creation API #620

jkva opened this issue Feb 16, 2022 · 0 comments

Comments

@jkva
Copy link
Contributor

jkva commented Feb 16, 2022

As demonstrated by the ActiveRecord::RecordNotUnique exception raised within Api::ResourcesController#create_many - https://sentry.io/organizations/coyote-org/issues/3016859111/

This likely happens because of the underlying Resource::find_or_initialize_by_canonical_id_or_source_uri - initlalisation doesn't create a record, the record is created by another parallel process, and when this Resource is saved, a RecordNotUnique exception is thrown via Postgres.

This code should be modified to use optimistic insertion by use of create_or_find_by.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants