Duplicate key error while following

Affected version
1.5.21

Zenexer

Active member
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

Top