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

Race condition on add_entity_relationship #9179

Closed
beck24 opened this Issue Dec 1, 2015 · 4 comments

Comments

Projects
None yet
3 participants
@beck24
Member

beck24 commented Dec 1, 2015

I'm occasionally getting this on one of our larger projects:

Duplicate entry '2276949-friend-2544817' for key 'guid_one'

QUERY: INSERT INTO elgg_entity_relationships
(guid_one, relationship, guid_two, time_created)
VALUES (2276949, 'friend', 2544817, 1448870065)

The only way I can see this occurring is by race condition whereby two threads call add_entity_relationship at the same time. They both pass the check_entity_relationship test and attempt to insert at the same time.

Potential fix:

INSERT INTO elgg_entity_relationships
(guid_one, relationship, guid_two, time_created)
VALUES (2276949, 'friend', 2544817, 1448870065)
ON DUPLICATE KEY UPDATE time_created = 1448870065

?

@mrclay

This comment has been minimized.

Show comment
Hide comment
@mrclay

mrclay Dec 1, 2015

Member

The fix seems OK, of course once this is fixed you'll hit other problems ;) Solution: set up the webserver so only 1 request can get handled at a time. [dusts hands] my job here is done.

Member

mrclay commented Dec 1, 2015

The fix seems OK, of course once this is fixed you'll hit other problems ;) Solution: set up the webserver so only 1 request can get handled at a time. [dusts hands] my job here is done.

@beck24

This comment has been minimized.

Show comment
Hide comment
@beck24

beck24 Dec 20, 2015

Member

haha, most likely :)

Member

beck24 commented Dec 20, 2015

haha, most likely :)

@topdog08

This comment has been minimized.

Show comment
Hide comment
@topdog08

topdog08 Dec 20, 2015

I have also seen this for elgg_users_entity when I got a spike in new users. Would same fix work there?

Duplicate entry '' for key 'username'

QUERY: INSERT into elgg_users_entity
(guid, name, username, password, salt, password_hash, email, language)
values (2595019,

topdog08 commented Dec 20, 2015

I have also seen this for elgg_users_entity when I got a spike in new users. Would same fix work there?

Duplicate entry '' for key 'username'

QUERY: INSERT into elgg_users_entity
(guid, name, username, password, salt, password_hash, email, language)
values (2595019,

@beck24

This comment has been minimized.

Show comment
Hide comment
@beck24

beck24 Dec 21, 2015

Member

No, the same fix could not work for that

Member

beck24 commented Dec 21, 2015

No, the same fix could not work for that

@beck24 beck24 closed this in 9e469da Dec 29, 2015

jeabakker added a commit to jeabakker/Elgg that referenced this issue Sep 20, 2018

fix(db): improved handling of duplicate relationship creation
ref #9179, #11975

Racing conditions exist where the check for an existing relationship
passes but the following insertion fails because of a duplicate key. The
result of the function was incorrect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment