Skip to content

Commit

Permalink
[core] Fix deadlock introduced by CUDTGroup::setOpt()
Browse files Browse the repository at this point in the history
  • Loading branch information
quink-black authored and maxsharabayko committed Dec 3, 2021
1 parent 8b68157 commit 244d2f4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,19 @@ void CUDTGroup::setOpt(SRT_SOCKOPT optName, const void* optval, int optlen)
HLOGC(gmlog.Debug, log << "... SPREADING to existing sockets.");
// This means that there are sockets already, so apply
// this option on them.
ScopedLock gg(m_GroupLock);
for (gli_t gi = m_Group.begin(); gi != m_Group.end(); ++gi)
std::vector<CUDTSocket*> ps_vec;
{
// Do copy to avoid deadlock. CUDT::setOpt() cannot be called directly inside this loop, because
// CUDT::setOpt() will lock m_ConnectionLock, which should be locked before m_GroupLock.
ScopedLock gg(m_GroupLock);
for (gli_t gi = m_Group.begin(); gi != m_Group.end(); ++gi)
{
ps_vec.push_back(gi->ps);
}
}
for (std::vector<CUDTSocket*>::iterator it = ps_vec.begin(); it != ps_vec.end(); ++it)
{
gi->ps->core().setOpt(optName, optval, optlen);
(*it)->core().setOpt(optName, optval, optlen);
}
}

Expand Down

0 comments on commit 244d2f4

Please sign in to comment.