mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltServer] Fixes potential race condition crash when managing connections
This commit is contained in:
committed by
Joseph Mattello
parent
eda4dd6aec
commit
e3c331c911
@@ -41,6 +41,7 @@ public class ConnectionManager<RequestHandlerType: RequestHandler>
|
||||
public var isStarted = false
|
||||
|
||||
private var connections = [Connection]()
|
||||
private let connectionsLock = NSLock()
|
||||
|
||||
public init(requestHandler: RequestHandlerType, connectionHandlers: [ConnectionHandler])
|
||||
{
|
||||
@@ -88,6 +89,9 @@ private extension ConnectionManager
|
||||
{
|
||||
func prepare(_ connection: Connection)
|
||||
{
|
||||
self.connectionsLock.lock()
|
||||
defer { self.connectionsLock.unlock() }
|
||||
|
||||
guard !self.connections.contains(where: { $0 === connection }) else { return }
|
||||
self.connections.append(connection)
|
||||
|
||||
@@ -96,6 +100,9 @@ private extension ConnectionManager
|
||||
|
||||
func disconnect(_ connection: Connection)
|
||||
{
|
||||
self.connectionsLock.lock()
|
||||
defer { self.connectionsLock.unlock() }
|
||||
|
||||
guard let index = self.connections.firstIndex(where: { $0 === connection }) else { return }
|
||||
self.connections.remove(at: index)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user