From 022d2d576c29c911220dc41dba1da0fb2a818326 Mon Sep 17 00:00:00 2001 From: ERussel Date: Wed, 23 Nov 2022 12:20:53 +0500 Subject: [PATCH] add lock for connection pool syncing --- .../ConnectionPool/ConnectionPool.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/novawallet/Common/Services/ChainRegistry/ConnectionPool/ConnectionPool.swift b/novawallet/Common/Services/ChainRegistry/ConnectionPool/ConnectionPool.swift index 25b43549ec..772f66b7d4 100644 --- a/novawallet/Common/Services/ChainRegistry/ConnectionPool/ConnectionPool.swift +++ b/novawallet/Common/Services/ChainRegistry/ConnectionPool/ConnectionPool.swift @@ -135,6 +135,12 @@ extension ConnectionPool: WebSocketEngineDelegate { extension ConnectionPool: ApplicationHandlerDelegate { func didReceiveDidBecomeActive(notification _: Notification) { + mutex.lock() + + defer { + mutex.unlock() + } + connections.values.forEach { wrapper in guard let connection = wrapper.target as? ChainConnection else { return @@ -145,6 +151,12 @@ extension ConnectionPool: ApplicationHandlerDelegate { } func didReceiveDidEnterBackground(notification _: Notification) { + mutex.lock() + + defer { + mutex.unlock() + } + connections.values.forEach { wrapper in guard let connection = wrapper.target as? ChainConnection else { return