Skip to content

Commit

Permalink
[core] Fixed incorrect group data sync on first connected socket
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Małecki authored and maxsharabayko committed Mar 17, 2021
1 parent 36fc361 commit 00e42d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
11 changes: 6 additions & 5 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,11 +1605,6 @@ int CUDTUnited::groupConnect(CUDTGroup* pg, SRT_SOCKGROUPCONFIG* targets, int ar
break;
}

if (was_empty)
{
g.syncWithSocket(ns->core(), HSD_INITIATOR);
}

HLOGC(aclog.Debug, log << "groupConnect: @" << sid << " connection successful, setting group OPEN (was "
<< (g.m_bOpened ? "ALREADY" : "NOT") << "), will " << (block_new_opened ? "" : "NOT ")
<< "block the connect call, status:" << SockStatusStr(st));
Expand Down Expand Up @@ -1911,6 +1906,12 @@ void CUDTUnited::deleteGroup(CUDTGroup* g)
using srt_logging::gmlog;

srt::sync::ScopedLock cg (m_GlobControlLock);
return deleteGroup_LOCKED(g);
}

// [[using locked(m_GlobControlLock)]]
void CUDTUnited::deleteGroup_LOCKED(CUDTGroup* g)
{
SRT_ASSERT(g->groupEmpty());

// After that the group is no longer findable by GroupKeeper
Expand Down
1 change: 1 addition & 0 deletions srtcore/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ friend class CRendezvousQueue;
}

void deleteGroup(CUDTGroup* g);
void deleteGroup_LOCKED(CUDTGroup* g);

// [[using locked(m_GlobControlLock)]]
CUDTGroup* findPeerGroup_LOCKED(SRTSOCKET peergroup)
Expand Down
14 changes: 11 additions & 3 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2953,6 +2953,9 @@ bool CUDT::interpretGroup(const int32_t groupdata[], size_t data_size SRT_ATR_UN
return false;
}

// Group existence is guarded, so we can now lock the group as well.
ScopedLock gl(*pg->exp_groupLock());

// Now we know the group exists, but it might still be closed
if (pg->closing())
{
Expand All @@ -2967,14 +2970,19 @@ bool CUDT::interpretGroup(const int32_t groupdata[], size_t data_size SRT_ATR_UN
// This is the first connection within this group, so this group
// has just been informed about the peer membership. Accept it.
pg->set_peerid(grpid);
HLOGC(cnlog.Debug, log << "HS/RSP: group $" << pg->id() << " mapped to peer mirror $" << pg->peerid());
HLOGC(cnlog.Debug, log << "HS/RSP: group $" << pg->id() << " -> peer $" << pg->peerid() << ", copying characteristic data");

// The call to syncWithSocket is copying
// some interesting data from the first connected
// socket. This should be only done for the first successful connection.
pg->syncWithSocket(*this, HSD_INITIATOR);
}
// Otherwise the peer id must be the same as existing, otherwise
// this group is considered already bound to another peer group.
// (Note that the peer group is peer-specific, and peer id numbers
// may repeat among sockets connected to groups established on
// different peers).
else if (pg->peerid() != grpid)
else if (peer != grpid)
{
LOGC(cnlog.Error, log << "IPE: HS/RSP: group membership responded for peer $" << grpid
<< " but the current socket's group $" << pg->id() << " has already a peer $" << peer);
Expand Down Expand Up @@ -3076,7 +3084,7 @@ SRTSOCKET CUDT::makeMePeerOf(SRTSOCKET peergroup, SRT_GROUP_TYPE gtp, uint32_t l
if (!gp->applyFlags(link_flags, m_SrtHsSide))
{
// Wrong settings. Must reject. Delete group.
s_UDTUnited.deleteGroup(gp);
s_UDTUnited.deleteGroup_LOCKED(gp);
return -1;
}

Expand Down

0 comments on commit 00e42d7

Please sign in to comment.