Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
server/onesync: fix deadlock caused by accidental recursive acquisiti…
…on of a SRW lock
  • Loading branch information
blattersturm committed Apr 12, 2019
1 parent f8cd327 commit b741f9a
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions code/components/citizen-server-impl/src/state/ServerGameState.cpp
Expand Up @@ -1291,17 +1291,18 @@ void ServerGameState::HandleClientDrop(const std::shared_ptr<fx::Client>& client
}

{
std::shared_lock<std::shared_mutex> lock(m_entitiesByIdMutex);

auto entity = m_entitiesById[set & 0xFFFF];
std::weak_ptr<sync::SyncEntityState> entity;

{
auto entityRef = entity.lock();
std::shared_lock<std::shared_mutex> lock(m_entitiesByIdMutex);
entity = m_entitiesById[set & 0xFFFF];
}

if (entityRef)
{
OnCloneRemove(entityRef);
}
auto entityRef = entity.lock();

if (entityRef)
{
OnCloneRemove(entityRef);
}
}

Expand Down Expand Up @@ -1867,13 +1868,15 @@ void ServerGameState::AttachToObject(fx::ServerInstanceBase* instance)
auto [data, lock] = GetClientData(this, client);
int used = 0;

std::shared_lock<std::shared_mutex> entityListLock(m_entitiesByIdMutex);

for (auto object : data->objectIds)
{
if (!m_entitiesById[object].expired())
std::shared_lock<std::shared_mutex> entityListLock(m_entitiesByIdMutex);

for (auto object : data->objectIds)
{
used++;
if (!m_entitiesById[object].expired())
{
used++;
}
}
}

Expand Down

0 comments on commit b741f9a

Please sign in to comment.