@@ -687,9 +687,15 @@ allowConnectionAsync' c corrId connId confId ownConnInfo =
687687 enqueueCommand c corrId connId (Just server) $ AClientCommand $ LET confId ownConnInfo
688688 _ -> throwE $ CMD PROHIBITED " allowConnectionAsync"
689689
690+ -- TODO
691+ -- Unlike `acceptContact` (synchronous version), `acceptContactAsync` uses `unacceptInvitation` in case of error,
692+ -- because we're not taking lock here. In practice it is less likely to fail because it doesn't involve network IO,
693+ -- and also it can't be triggered by user concurrently several times in a row. It could be improved similarly to
694+ -- `acceptContact` by creating a new map for invitation locks and taking lock here, and removing `unacceptInvitation`
695+ -- while marking invitation as accepted inside "lock level transaction" after successful `joinConnAsync`.
690696acceptContactAsync' :: AgentClient -> ACorrId -> Bool -> InvitationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AM ConnId
691697acceptContactAsync' c corrId enableNtfs invId ownConnInfo pqSupport subMode = do
692- Invitation {contactConnId, connReq} <- withStore c ( ` getInvitation` invId)
698+ Invitation {contactConnId, connReq} <- withStore c $ \ db -> getInvitation db " acceptContactAsync' " invId
693699 withStore c (`getConn` contactConnId) >>= \ case
694700 SomeConn _ (ContactConnection ConnData {userId} _) -> do
695701 withStore' c $ \ db -> acceptInvitation db invId ownConnInfo
@@ -809,7 +815,7 @@ newConnToJoin c userId connId enableNtfs cReq pqSup = case cReq of
809815
810816newConnToAccept :: AgentClient -> ConnId -> Bool -> ConfirmationId -> PQSupport -> AM ConnId
811817newConnToAccept c connId enableNtfs invId pqSup = do
812- Invitation {connReq, contactConnId} <- withStore c ( ` getInvitation` invId)
818+ Invitation {connReq, contactConnId} <- withStore c $ \ db -> getInvitation db " newConnToAccept " invId
813819 withStore c (`getConn` contactConnId) >>= \ case
814820 SomeConn _ (ContactConnection ConnData {userId} _) ->
815821 newConnToJoin c userId connId enableNtfs connReq pqSup
@@ -941,13 +947,12 @@ allowConnection' c connId confId ownConnInfo = withConnLock c connId "allowConne
941947-- | Accept contact (ACPT command) in Reader monad
942948acceptContact' :: AgentClient -> ConnId -> Bool -> InvitationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AM SndQueueSecured
943949acceptContact' c connId enableNtfs invId ownConnInfo pqSupport subMode = withConnLock c connId " acceptContact" $ do
944- Invitation {contactConnId, connReq} <- withStore c ( ` getInvitation` invId)
950+ Invitation {contactConnId, connReq} <- withStore c $ \ db -> getInvitation db " acceptContact' " invId
945951 withStore c (`getConn` contactConnId) >>= \ case
946952 SomeConn _ (ContactConnection ConnData {userId} _) -> do
953+ sqSecured <- joinConn c userId connId enableNtfs connReq ownConnInfo pqSupport subMode
947954 withStore' c $ \ db -> acceptInvitation db invId ownConnInfo
948- joinConn c userId connId enableNtfs connReq ownConnInfo pqSupport subMode `catchAgentError` \ err -> do
949- withStore' c (`unacceptInvitation` invId)
950- throwE err
955+ pure sqSecured
951956 _ -> throwE $ CMD PROHIBITED " acceptContact"
952957
953958-- | Reject contact (RJCT command) in Reader monad
0 commit comments