From 96c38466d20203a561a5bc3bba560c9d9fd6d754 Mon Sep 17 00:00:00 2001 From: Janis Date: Wed, 5 Nov 2025 11:19:37 +0100 Subject: [PATCH] fix: improve lock handling in user session interactions (#36) Reviewed-on: https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/pulls/36 Reviewed-by: lq64 Co-authored-by: Janis Co-committed-by: Janis --- knockoutwhistweb/app/logic/game/GameLobby.scala | 2 +- knockoutwhistweb/app/model/sessions/UserSession.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/knockoutwhistweb/app/logic/game/GameLobby.scala b/knockoutwhistweb/app/logic/game/GameLobby.scala index a43e41a..6743bdb 100644 --- a/knockoutwhistweb/app/logic/game/GameLobby.scala +++ b/knockoutwhistweb/app/logic/game/GameLobby.scala @@ -185,7 +185,7 @@ class GameLobby private( } private def getPlayerInteractable(userSession: UserSession, iType: InteractionType): AbstractPlayer = { - if (!Thread.holdsLock(userSession.lock)) { + if (!userSession.lock.isHeldByCurrentThread) { throw new IllegalStateException("The user session is not locked!") } if (userSession.canInteract.isEmpty || userSession.canInteract.get != iType) { diff --git a/knockoutwhistweb/app/model/sessions/UserSession.scala b/knockoutwhistweb/app/model/sessions/UserSession.scala index 148ed50..94e56ff 100644 --- a/knockoutwhistweb/app/model/sessions/UserSession.scala +++ b/knockoutwhistweb/app/model/sessions/UserSession.scala @@ -9,7 +9,7 @@ import java.util.concurrent.locks.{Lock, ReentrantLock} class UserSession(user: User, val host: Boolean) extends PlayerSession { var canInteract: Option[InteractionType] = None - val lock: Lock = ReentrantLock() + val lock: ReentrantLock = ReentrantLock() override def updatePlayer(event: SimpleEvent): Unit = { event match {