Fix crash (accessing already deleted client record) by reverting to old client removing handling + throwTo
authorunc0rr
Wed, 09 Mar 2011 22:11:29 +0300
changeset 4996 76ef3d8bd78e
parent 4995 d3ca68e4860e
child 4997 28c670367e6c
Fix crash (accessing already deleted client record) by reverting to old client removing handling + throwTo
gameServer/ClientIO.hs
gameServer/CoreTypes.hs
gameServer/OfficialServer/DBInteraction.hs
--- a/gameServer/ClientIO.hs	Wed Mar 09 21:41:16 2011 +0300
+++ b/gameServer/ClientIO.hs	Wed Mar 09 22:11:29 2011 +0300
@@ -45,13 +45,16 @@
 
         sendPacket packet = writeChan chan $ ClientMessage (ci, packet)
 
-
 clientRecvLoop :: Socket -> Chan CoreMessage -> ClientIndex -> IO ()
-clientRecvLoop s chan ci = do
-    msg <- (listenLoop s chan ci >> return "Connection closed") `catch` (return . B.pack . show)
-    clientOff msg
+clientRecvLoop s chan ci =
+    do
+        msg <- (listenLoop s chan ci >> return "Connection closed") `catch` (return . B.pack . show)
+        clientOff msg
+    `Exception.finally`
+        remove
     where
         clientOff msg = writeChan chan $ ClientMessage (ci, ["QUIT", msg])
+        remove = writeChan chan $ Remove ci
 
 
 
@@ -65,8 +68,7 @@
     if isQuit answer then
         do
         Exception.handle (\(_ :: Exception.IOException) -> putStrLn "error on sClose") $ sClose s
-        killThread tId
-        writeChan cChan $ Remove ci
+        Exception.throwTo tId ShutdownThreadException
         else
         clientSendLoop s tId cChan chan ci
 
--- a/gameServer/CoreTypes.hs	Wed Mar 09 21:41:16 2011 +0300
+++ b/gameServer/CoreTypes.hs	Wed Mar 09 22:11:29 2011 +0300
@@ -205,3 +205,8 @@
      deriving (Show, Typeable)
 
 instance Exception ShutdownException
+
+data ShutdownThreadException = ShutdownThreadException
+     deriving (Show, Typeable)
+
+instance Exception ShutdownThreadException
--- a/gameServer/OfficialServer/DBInteraction.hs	Wed Mar 09 21:41:16 2011 +0300
+++ b/gameServer/OfficialServer/DBInteraction.hs	Wed Mar 09 22:11:29 2011 +0300
@@ -36,7 +36,8 @@
         ClearCache -> return ()
         SendStats {} -> return ()
 
---dbConnectionLoop :: forall b. (ServerInfo c) -> IO b
+dbConnectionLoop :: ServerInfo -> IO ()
+
 #if defined(OFFICIAL_SERVER)
 flushRequests :: ServerInfo -> IO ()
 flushRequests si = do
@@ -115,7 +116,6 @@
     threadDelay (3000000)
     pipeDbConnection updatedCache si newErrNum
 
-dbConnectionLoop :: ServerInfo -> IO ()
 dbConnectionLoop si =
         if (not . B.null $ dbHost si) then
             pipeDbConnection Map.empty si 0