Skip to content

Commit

Permalink
[core] Fixed group synchronization of accepted sockets.
Browse files Browse the repository at this point in the history
Fixes #2941.
  • Loading branch information
maxsharabayko committed Apr 30, 2024
1 parent 57a4d9f commit 07859c8
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5755,14 +5755,6 @@ void srt::CUDT::rewriteHandshakeData(const sockaddr_any& peer, CHandShake& w_hs)
void srt::CUDT::acceptAndRespond(const sockaddr_any& agent, const sockaddr_any& peer, const CPacket& hspkt, CHandShake& w_hs)
{
HLOGC(cnlog.Debug, log << CONID() << "acceptAndRespond: setting up data according to handshake");
#if ENABLE_BONDING
// Keep the group alive for the lifetime of this function,
// and do it BEFORE acquiring m_ConnectionLock to avoid
// lock inversion.
// This will check if a socket belongs to a group and if so
// it will remember this group and keep it alive here.
CUDTUnited::GroupKeeper group_keeper(uglobal(), m_parent);
#endif

ScopedLock cg(m_ConnectionLock);

Expand Down Expand Up @@ -5850,6 +5842,16 @@ void srt::CUDT::acceptAndRespond(const sockaddr_any& agent, const sockaddr_any&
throw CUDTException(MJ_SETUP, MN_REJECTED, 0);
}

#if ENABLE_BONDING
// The socket and the group are only linked to each other after interpretSrtHandshake(..) has been called.
// Keep the group alive for the lifetime of this function,
// and do it BEFORE acquiring m_ConnectionLock to avoid
// lock inversion.
// This will check if a socket belongs to a group and if so
// it will remember this group and keep it alive here.
CUDTUnited::GroupKeeper group_keeper(uglobal(), m_parent);
#endif

if (!prepareBuffers(NULL))
{
HLOGC(cnlog.Debug,
Expand Down

0 comments on commit 07859c8

Please sign in to comment.