@@ -145,10 +145,12 @@ module Simplex.Messaging.Agent
145145where
146146
147147import Control.Applicative ((<|>) )
148+ import Control.Concurrent (myThreadId )
148149import Control.Concurrent.STM (retry )
149150import Control.Logger.Simple
150151import Control.Monad
151152import Control.Monad.Except
153+ import Debug.Trace (traceIO )
152154import Control.Monad.Reader
153155import Control.Monad.Trans.Except
154156import Crypto.Random (ChaChaDRG )
@@ -1841,6 +1843,9 @@ sendMessagesB_ c reqs connIds = withConnLocks c connIds "sendMessages" $ do
18411843
18421844enqueueCommand :: AgentClient -> ACorrId -> ConnId -> Maybe SMPServer -> AgentCommand -> AM ()
18431845enqueueCommand c corrId connId server aCommand = do
1846+ liftIO $ do
1847+ tid <- myThreadId
1848+ traceIO $ " ENQUEUE_CMD connId=" <> show connId <> " cmd=" <> show (agentCommandTag aCommand) <> " tid=" <> show tid
18441849 withStore c $ \ db -> createCommand db corrId connId server aCommand
18451850 lift . void $ getAsyncCmdWorker True c connId server
18461851
@@ -1869,7 +1874,13 @@ runCommandProcessing c connId server_ Worker {doWork} = do
18691874 ri <- asks $ messageRetryInterval . config -- different retry interval?
18701875 forever $ do
18711876 endAgentOp c AOSndNetwork
1877+ liftIO $ do
1878+ tid <- myThreadId
1879+ traceIO $ " ASYNC_CMD wait connId=" <> show connId <> " tid=" <> show tid
18721880 lift $ waitForWork doWork
1881+ liftIO $ do
1882+ tid <- myThreadId
1883+ traceIO $ " ASYNC_CMD woke connId=" <> show connId <> " tid=" <> show tid
18731884 liftIO $ throwWhenInactive c
18741885 atomically $ beginAgentOperation c AOSndNetwork
18751886 withWork c doWork (\ db -> getPendingServerCommand db connId server_) $ runProcessCmd (riFast ri)
@@ -2161,7 +2172,10 @@ getDeliveryWorker hasWork c sq =
21612172 pure (w, retryLock)
21622173
21632174submitPendingMsg :: AgentClient -> SndQueue -> AM' ()
2164- submitPendingMsg c sq = do
2175+ submitPendingMsg c sq@ SndQueue {connId = sqConnId} = do
2176+ liftIO $ do
2177+ tid <- myThreadId
2178+ traceIO $ " SUBMIT_PENDING connId=" <> show sqConnId <> " tid=" <> show tid
21652179 atomically $ modifyTVar' (msgDeliveryOp c) $ \ s -> s {opsInProgress = opsInProgress s + 1 }
21662180 void $ getDeliveryWorker True c sq
21672181
@@ -2170,12 +2184,21 @@ runSmpQueueMsgDelivery c sq@SndQueue {userId, connId, server, queueMode} (Worker
21702184 AgentConfig {messageRetryInterval = ri, messageTimeout, helloTimeout, quotaExceededTimeout} <- asks config
21712185 forever $ do
21722186 endAgentOp c AOSndNetwork
2187+ liftIO $ do
2188+ tid <- myThreadId
2189+ traceIO $ " DELIVERY wait connId=" <> show connId <> " tid=" <> show tid
21732190 lift $ waitForWork doWork
2191+ liftIO $ do
2192+ tid <- myThreadId
2193+ traceIO $ " DELIVERY woke connId=" <> show connId <> " tid=" <> show tid
21742194 liftIO $ throwWhenInactive c
21752195 liftIO $ throwWhenNoDelivery c sq
21762196 atomically $ beginAgentOperation c AOSndNetwork
21772197 withWork c doWork (\ db -> getPendingQueueMsg db connId sq) $
21782198 \ (rq_, PendingMsgData {msgId, msgType, msgBody, pqEncryption, msgFlags, msgRetryState, internalTs, internalSndId, prevMsgHash, pendingMsgPrepData_}) -> do
2199+ liftIO $ do
2200+ tid <- myThreadId
2201+ traceIO $ " DELIVERY send connId=" <> show connId <> " msgType=" <> show msgType <> " tid=" <> show tid
21792202 endAgentOp c AOMsgDelivery -- this operation begins in submitPendingMsg
21802203 let mId = unId msgId
21812204 ri' = maybe id updateRetryInterval2 msgRetryState ri
0 commit comments