From 8d5a26c47159212bd2a30d0d49bc924d03ed4c21 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 10 Jun 2021 10:15:04 +0200 Subject: [PATCH] Fall back get participant in case session is gone In some concurrent request scenarios, the session of a participant might expire just after its id got retrieved. To avoid unexpected behavior, if the participant could not be found by session id, fall back to getting it by user id. Fixes issue where a room can sometimes not be deleted from the UI due to a concurrent request that removes the session id. Signed-off-by: Vincent Petry --- lib/Middleware/InjectionMiddleware.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Middleware/InjectionMiddleware.php b/lib/Middleware/InjectionMiddleware.php index 9d099d69746..5b3c1a6e8bb 100644 --- a/lib/Middleware/InjectionMiddleware.php +++ b/lib/Middleware/InjectionMiddleware.php @@ -151,13 +151,22 @@ protected function getLoggedInOrGuest(AEnvironmentAwareController $controller, b $token = $this->request->getParam('token'); $room = $this->manager->getRoomForUserByToken($token, $this->userId); $controller->setRoom($room); + $participant = null; $sessionId = $this->talkSession->getSessionForRoom($token); if ($sessionId !== null) { - $participant = $room->getParticipantBySession($sessionId); - } else { + try { + $participant = $room->getParticipantBySession($sessionId); + } catch (ParticipantNotFoundException $e) { + // ignore and fall back in case a concurrent request might have + // invalidated the session + } + } + + if ($participant === null) { $participant = $room->getParticipant($this->userId); } + $controller->setParticipant($participant); if ($moderatorRequired && !$participant->hasModeratorPermissions()) {