Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix concurrent writes to mutable keepalive set #585

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/main/scala/KeepAlive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package lila.ws

import org.apache.pekko.actor.typed.Scheduler

import java.util.concurrent.atomic.AtomicReference

import ipc.*

final class KeepAlive(lila: Lila, scheduler: Scheduler)(using Executor):
Expand Down Expand Up @@ -32,11 +34,8 @@ object KeepAlive:

final class AliveRooms:

private val rooms = collection.mutable.Set[RoomId]()
private val rooms: AtomicReference[Set[RoomId]] = AtomicReference(Set.empty)

def apply(roomId: RoomId) = rooms += roomId
def apply(roomId: RoomId): Unit = rooms.getAndUpdate(_ + roomId)

def getAndClear: LilaIn.KeepAlives =
val ret = LilaIn.KeepAlives(rooms.toSet)
rooms.clear()
ret
def getAndClear: LilaIn.KeepAlives = LilaIn.KeepAlives(rooms.getAndUpdate(_ => Set.empty))
Loading