core: do not connect to a group whose member is already connected

Connecting to a prepared group whose host or relay member already had a
connection created a second one for the same member -

  UNIQUE constraint failed: connections.group_member_id

reachable by connecting again from a second view of the same group. joinContact
advances the connection past ConnPrepared only after the agent call returns, so
a join that failed is resumed by the ConnPrepared branch above and reaching this
one means the join already succeeded; there is no case where connecting again is
what the caller wants. Replaces a connect' call the code already questioned.

The two tests reach this error only because owner members are now re-used, so
they cover both halves: without either change they fail on a constraint instead.
This commit is contained in:
Narasimha-sc committed 2026-08-20 14:03:37 +00:00
1 parent be8d51b642
commit 66d6466a9e
3 files changed
+52 -1

No files matched your search

+4 -1
View File
@@ -3771,7 +3771,10 @@ processChatCommand cxt nm = \case
Nothing -> connect' groupLinkId Nothing (Just $ Just gInfo)
Just conn@Connection {connStatus, xContactId} -> case connStatus of
ConnPrepared -> joinPreparedConn' xContactId conn (Just $ Just gInfo)
_ -> connect' groupLinkId xContactId (Just $ Just gInfo) -- why not "already connected" for host member?
-- the connection is only advanced past ConnPrepared once the join succeeded (see joinContact),
-- so retrying a join that failed reuses it above, and reaching here means it already joined -
-- connecting again would create a second connection for the same member.
_ -> throwCmdError "group is already being joined"
Nothing ->
withFastStore' (\db -> getConnReqContactXContactId db cxt user cReqHash1 cReqHash2) >>= \case
Right ct@Contact {activeConn} -> case groupLinkId of