From 33bd0ab42ddf87ed9338421ed344c3a56aebb971 Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Date: Sun, 21 Apr 2024 21:05:00 +0300 Subject: [PATCH] transport: extend connection timeout for socks --- src/Simplex/Messaging/Client.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Simplex/Messaging/Client.hs b/src/Simplex/Messaging/Client.hs index 6d0e16865..6babb2a95 100644 --- a/src/Simplex/Messaging/Client.hs +++ b/src/Simplex/Messaging/Client.hs @@ -360,13 +360,17 @@ getProtocolClient g transportSession@(_, srv, _) cfg@ProtocolClientConfig {qSize runClient :: (ServiceName, ATransport) -> TransportHost -> PClient v err msg -> IO (Either (ProtocolClientError err) (ProtocolClient v err msg)) runClient (port', ATransport t) useHost c = do cVar <- newEmptyTMVarIO - let tcConfig = transportClientConfig networkConfig + let (connectTimeout, tcConfig) = case transportClientConfig networkConfig of + tcc@TransportClientConfig {socksProxy = Nothing} -> (tcpConnectTimeout, tcc) + tcc@TransportClientConfig {socksProxy = Just _} -> + let extended = tcpConnectTimeout + tcpTimeout -- typically, extra time for establishing TOR circuits + in (extended, tcc {tcpConnectTimeout = extended} :: TransportClientConfig) username = proxyUsername transportSession action <- async $ runTransportClient tcConfig (Just username) useHost port' (Just $ keyHash srv) (client t c cVar) `finally` atomically (tryPutTMVar cVar $ Left PCENetworkError) - c_ <- (tcpConnectTimeout + tcpTimeout) `timeout` atomically (takeTMVar cVar) + c_ <- (connectTimeout + tcpTimeout) `timeout` atomically (takeTMVar cVar) case c_ of Just (Right c') -> pure $ Right c' {action = Just action} Just (Left e) -> pure $ Left e