Skip to content

Conversation

@epoberezkin
Copy link
Member

No description provided.

@epoberezkin epoberezkin requested a review from spaced4ndy as a code owner June 24, 2025 13:10
@epoberezkin epoberezkin marked this pull request as draft June 24, 2025 13:10
@epoberezkin epoberezkin force-pushed the ep/agent-connect-errors branch from 9039b6a to 833be46 Compare June 24, 2025 20:38
@epoberezkin epoberezkin changed the title agent: better handling errors during connection handshake WIP agent: better handling errors during connection handshake retries Jun 25, 2025
@epoberezkin epoberezkin marked this pull request as ready for review June 25, 2025 12:09
@epoberezkin epoberezkin force-pushed the ep/agent-connect-errors branch from 56ed24f to 6eb362e Compare June 25, 2025 12:15
(Right agentMsgBody, CR.SMDNoChange) ->
case skipped of
CR.SMDNoChange -> pure ()
_ -> logWarn "conf: skipped confirmations"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows retries confirmations that result in skipped messages

let pqInitKeys = CR.joinContactInitialKeys (v >= pqdrSMPAgentVersion) pqSup
(CCLink cReq _, service) <- case conn of
NewConnection _ -> newRcvConnSrv c userId connId enableNtfs SCMInvitation Nothing Nothing pqInitKeys subMode srv
RcvConnection _ rq -> mkJoinInvitation rq pqInitKeys
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows repeat joins to contact address when the queue is created but the error happens when sending invitation

NewConnection _ -> doJoin Nothing Nothing
SndConnection _ sq -> doJoin Nothing (Just sq)
DuplexConnection _ (rq@RcvQueue {status = New} :| _) (sq@SndQueue {status = sqStatus} :| _)
| sqStatus == New || sqStatus == Secured -> doJoin (Just rq) (Just sq)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows retries after initiator's queue is secured

mkAgentConfirmation c cData rq_ sq srv connInfo subMode = do
(qInfo, service) <- case rq_ of
Nothing -> createReplyQueue c cData sq subMode srv
Just rq@RcvQueue {smpClientVersion = v, clientService} -> pure (SMPQueueInfo v $ rcvSMPQueueAddress rq, dbServiceId <$> clientService)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows retries after queue is created, but the confirmation failed to sent.

logInfo . decodeUtf8 $ "Agent connected to " <> showServer srv <> " (user " <> bshow userId <> maybe "" (" for entity " <>) entityId_ <> ")"
atomically $ putTMVar (sessionVar v) (Right client)
atomically $ writeTBQueue (subQ c) ("", "", AEvt SAENone $ hostEvent CONNECT client)
liftIO $ nonBlockingWriteTBQueue (subQ c) ("", "", AEvt SAENone $ hostEvent CONNECT client)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be hanging in the test because the queue is small, but in theory can reach capacity in the app too if there are too many events.

@epoberezkin epoberezkin merged commit b4bcfd3 into master Jun 25, 2025
3 of 4 checks passed
@epoberezkin epoberezkin deleted the ep/agent-connect-errors branch June 25, 2025 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant