mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2025-01-02 23:20:08 +00:00
Fix race condition leading to multiple leaves
This commit is contained in:
parent
70dfcc663d
commit
c4fb4c198b
@ -240,9 +240,23 @@ public static function getDeadUsers() {
|
||||
$time = TIME_NOW;
|
||||
}
|
||||
|
||||
$sql = "SELECT userID
|
||||
FROM wcf".WCF_N."_user
|
||||
WHERE chatRoomID IS NOT NULL
|
||||
AND chatLastActivity < ?
|
||||
FOR UPDATE";
|
||||
$statement = WCF::getDB()->prepareStatement($sql);
|
||||
$statement->execute([ $time - 30 ]);
|
||||
$userIDs = [];
|
||||
while ($userID = $statement->fetchColumn()) $userIDs[] = $userID;
|
||||
|
||||
$userList = new \wcf\data\user\UserList();
|
||||
$userList->getConditionBuilder()->add('user_table.chatRoomID IS NOT NULL', array());
|
||||
$userList->getConditionBuilder()->add('user_table.chatLastActivity < ?', array($time - 30));
|
||||
if (!empty($userIDs)) {
|
||||
$userList->getConditionBuilder()->add('user_table.userID IN (?)', array($userIDs));
|
||||
}
|
||||
else {
|
||||
$userList->getConditionBuilder()->add('1 = 0', []);
|
||||
}
|
||||
|
||||
$userList->readObjects();
|
||||
|
||||
|
@ -329,6 +329,7 @@ public function leave() {
|
||||
* Forces dead users to leave the chat.
|
||||
*/
|
||||
public function removeDeadUsers() {
|
||||
WCF::getDB()->beginTransaction();
|
||||
$deadUsers = Room::getDeadUsers();
|
||||
|
||||
foreach ($deadUsers as $deadUser) {
|
||||
@ -337,6 +338,7 @@ public function removeDeadUsers() {
|
||||
));
|
||||
$roomAction->executeAction();
|
||||
}
|
||||
WCF::getDB()->commitTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user