From 6c750eb5df450edeed93e993352d9a5540cea81b Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Thu, 18 Dec 2025 14:03:44 +0000 Subject: [PATCH] core: fix remote desktop failing to receive new events after agent error (#6512) --- src/Simplex/Chat/Remote.hs | 10 +++++++--- src/Simplex/Chat/Types.hs | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Simplex/Chat/Remote.hs b/src/Simplex/Chat/Remote.hs index a706bfc0de..255af5f318 100644 --- a/src/Simplex/Chat/Remote.hs +++ b/src/Simplex/Chat/Remote.hs @@ -233,9 +233,13 @@ startRemoteHost rh_ rcAddrPrefs_ port_ = do pollEvents :: RemoteHostId -> RemoteHostClient -> CM () pollEvents rhId rhClient = do oq <- asks outputQ - forever $ do - r_ <- liftRH rhId $ remoteRecv rhClient 10000000 - forM r_ $ \r -> atomically $ writeTBQueue oq (Just rhId, r) + forever $ + handlePollError oq $ do + r_ <- liftRH rhId $ remoteRecv rhClient 10000000 + forM_ r_ $ \r -> atomically $ writeTBQueue oq (Just rhId, r) + where + handlePollError oq a = a `catchAllErrors` \e -> + atomically $ writeTBQueue oq (Just rhId, Left e) httpError :: RemoteHostId -> HTTP2ClientError -> ChatError httpError rhId = ChatErrorRemoteHost (RHId rhId) . RHEProtocolError . RPEHTTP2 . tshow diff --git a/src/Simplex/Chat/Types.hs b/src/Simplex/Chat/Types.hs index 667660c97b..c08c0827ae 100644 --- a/src/Simplex/Chat/Types.hs +++ b/src/Simplex/Chat/Types.hs @@ -36,6 +36,7 @@ import qualified Data.Aeson.TH as JQ import qualified Data.Attoparsec.ByteString.Char8 as A import qualified Data.ByteString.Base64 as B64 import Data.ByteString.Char8 (ByteString, pack, unpack) +import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Lazy as LB import Data.Functor (($>)) import Data.Int (Int64) @@ -1411,7 +1412,7 @@ instance ToField AgentConnId where toField (AgentConnId m) = toField $ Binary m instance StrEncoding AgentConnId where strEncode (AgentConnId connId) = strEncode connId strDecode s = AgentConnId <$> strDecode s - strP = AgentConnId <$> strP + strP = AgentConnId <$> (strP <|> pure B.empty) instance FromJSON AgentConnId where parseJSON = strParseJSON "AgentConnId"