Skip to content

Commit 3e0043d

Browse files
committed
smp server: do not create messaging queues in SMP proxy to prevent deadlock in processing
1 parent 5d2b37f commit 3e0043d

4 files changed

Lines changed: 6 additions & 7 deletions

File tree

src/Simplex/Messaging/Agent/Store/SQLite.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import Data.Bits (xor)
5050
import Data.ByteArray (ScrubbedBytes)
5151
import qualified Data.ByteArray as BA
5252
import Data.ByteString (ByteString)
53-
import qualified Data.ByteString as B
5453
import Data.Functor (($>))
5554
import Data.IORef
5655
import Data.Maybe (fromMaybe)

src/Simplex/Messaging/Client/Agent.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ data SMPClientAgentConfig = SMPClientAgentConfig
107107
{ smpCfg :: ProtocolClientConfig SMPVersion,
108108
reconnectInterval :: RetryInterval,
109109
persistErrorInterval :: NominalDiffTime,
110-
msgQSize :: Natural,
110+
msgQSize :: Maybe Natural,
111111
agentQSize :: Natural,
112112
agentSubsBatchSize :: Int,
113113
ownServerDomains :: [ByteString]
@@ -124,7 +124,7 @@ defaultSMPClientAgentConfig =
124124
maxInterval = 10 * second
125125
},
126126
persistErrorInterval = 30, -- seconds
127-
msgQSize = 2048,
127+
msgQSize = Just 2048,
128128
agentQSize = 2048,
129129
agentSubsBatchSize = 1360,
130130
ownServerDomains = []
@@ -162,9 +162,8 @@ newSMPClientAgent :: SParty p -> SMPClientAgentConfig -> Maybe DBService -> TVar
162162
newSMPClientAgent agentParty agentCfg@SMPClientAgentConfig {msgQSize, agentQSize} dbService randomDrg = do
163163
active <- newTVarIO True
164164
startedAt <- getCurrentTime
165-
-- Only subscribing agents receive server transmissions. A queue nobody reads fills with late
166-
-- responses (Client.hs, processMsg) until the client's `process` thread blocks writing to it.
167-
msgQ <- forM (serviceParty agentParty) $ \_ -> newTBQueueIO msgQSize
165+
-- Only subscribing agents receive server transmissions, should not be created until processed to prevent deadlock.
166+
msgQ <- mapM newTBQueueIO msgQSize
168167
agentQ <- newTBQueueIO agentQSize
169168
smpClients <- TM.emptyIO
170169
smpSessions <- TM.emptyIO

src/Simplex/Messaging/Server/Main.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ smpServerCLI_ generateSite serveStaticFiles attachStaticFiles cfgPath logPath =
604604
}
605605
},
606606
ownServerDomains = either (const []) textToOwnServers $ lookupValue "PROXY" "own_server_domains" ini,
607+
msgQSize = Nothing, -- to prevent accumulation of late responses, and deadlocks in SMP proxy
607608
persistErrorInterval = 30 -- seconds
608609
},
609610
allowSMPProxy = True,

tests/SMPClient.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ cfgMS msType = withStoreCfg (testServerStoreConfig msType) $ \serverStoreCfg ->
275275
smpServerVRange = supportedServerSMPRelayVRange,
276276
transportConfig = mkTransportServerConfig True (Just alpnSupportedSMPHandshakes) True,
277277
controlPort = Nothing,
278-
smpAgentCfg = defaultSMPClientAgentConfig {persistErrorInterval = 1}, -- seconds
278+
smpAgentCfg = defaultSMPClientAgentConfig {persistErrorInterval = 1, msgQSize = Nothing}, -- seconds
279279
allowSMPProxy = False,
280280
serverClientConcurrency = 2,
281281
serverResolverConcurrency = defaultNameResolverConcurrency,

0 commit comments

Comments
 (0)