1
0
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:
Tim Düsterhus 2016-05-31 23:29:17 +02:00
parent 70dfcc663d
commit c4fb4c198b
2 changed files with 18 additions and 2 deletions

View File

@ -240,9 +240,23 @@ public static function getDeadUsers() {
$time = TIME_NOW; $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 = new \wcf\data\user\UserList();
$userList->getConditionBuilder()->add('user_table.chatRoomID IS NOT NULL', array()); if (!empty($userIDs)) {
$userList->getConditionBuilder()->add('user_table.chatLastActivity < ?', array($time - 30)); $userList->getConditionBuilder()->add('user_table.userID IN (?)', array($userIDs));
}
else {
$userList->getConditionBuilder()->add('1 = 0', []);
}
$userList->readObjects(); $userList->readObjects();

View File

@ -329,6 +329,7 @@ public function leave() {
* Forces dead users to leave the chat. * Forces dead users to leave the chat.
*/ */
public function removeDeadUsers() { public function removeDeadUsers() {
WCF::getDB()->beginTransaction();
$deadUsers = Room::getDeadUsers(); $deadUsers = Room::getDeadUsers();
foreach ($deadUsers as $deadUser) { foreach ($deadUsers as $deadUser) {
@ -337,6 +338,7 @@ public function removeDeadUsers() {
)); ));
$roomAction->executeAction(); $roomAction->executeAction();
} }
WCF::getDB()->commitTransaction();
} }
/** /**