Fixed Duplicate key error while following

PaulB

Well-known member
Affected version
1.5.21
In Model/User.php, function follow, around line 1760:

The ordering of beginTransaction and removeDuplicateFollowUserIds is wrong. Because removeDuplicateFollowUserIds is performed outside the transaction, a race condition occurs. If the user is experiencing internet connectivity issues and ends up sending multiple follow requests nearly simultaneously, the following can happen:

Code:
Zend_Db_Statement_Mysqli_Exception: Mysqli statement execute error : Duplicate entry '123-456' for key 'PRIMARY' - library/Zend/Db/Statement/Mysqli.php:214

To resolve this, beginTransaction needs to be called prior to removeDuplicateFollowUserIds.

Basic patch with minimal testing attached.
 

Attachments

Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (1.5.24).

Change log:
Attempt to avoid a duplicate key race condition when following a user.
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Back
Top Bottom