smp server: possible race when creating client that might lead to memory leak (#1260)

This commit is contained in:
Evgeny
2024-08-20 12:25:58 +01:00
committed by GitHub
parent 1cbf8c0015
commit ac930dff30
2 changed files with 23 additions and 18 deletions
+3 -4
View File
@@ -127,7 +127,7 @@ data Env = Env
serverStats :: ServerStats,
sockets :: SocketState,
clientSeq :: TVar ClientId,
clients :: TVar (IntMap Client),
clients :: TVar (IntMap (Maybe Client)),
proxyAgent :: ProxyAgent -- senders served on this proxy
}
@@ -183,9 +183,8 @@ newServer = do
savingLock <- atomically createLock
return Server {subscribedQ, subscribers, ntfSubscribedQ, notifiers, savingLock}
newClient :: TVar ClientId -> Natural -> VersionSMP -> ByteString -> SystemTime -> IO Client
newClient nextClientId qSize thVersion sessionId createdAt = do
clientId <- atomically $ stateTVar nextClientId $ \next -> (next, next + 1)
newClient :: ClientId -> Natural -> VersionSMP -> ByteString -> SystemTime -> IO Client
newClient clientId qSize thVersion sessionId createdAt = do
subscriptions <- TM.emptyIO
ntfSubscriptions <- TM.emptyIO
rcvQ <- newTBQueueIO qSize