Skip to content

Commit b741f9a

Browse files
committed
server/onesync: fix deadlock caused by accidental recursive acquisition of a SRW lock
1 parent f8cd327 commit b741f9a

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

code/components/citizen-server-impl/src/state/ServerGameState.cpp

+16-13
Original file line numberDiff line numberDiff line change
@@ -1291,17 +1291,18 @@ void ServerGameState::HandleClientDrop(const std::shared_ptr<fx::Client>& client
12911291
}
12921292

12931293
{
1294-
std::shared_lock<std::shared_mutex> lock(m_entitiesByIdMutex);
1295-
1296-
auto entity = m_entitiesById[set & 0xFFFF];
1294+
std::weak_ptr<sync::SyncEntityState> entity;
12971295

12981296
{
1299-
auto entityRef = entity.lock();
1297+
std::shared_lock<std::shared_mutex> lock(m_entitiesByIdMutex);
1298+
entity = m_entitiesById[set & 0xFFFF];
1299+
}
13001300

1301-
if (entityRef)
1302-
{
1303-
OnCloneRemove(entityRef);
1304-
}
1301+
auto entityRef = entity.lock();
1302+
1303+
if (entityRef)
1304+
{
1305+
OnCloneRemove(entityRef);
13051306
}
13061307
}
13071308

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

1870-
std::shared_lock<std::shared_mutex> entityListLock(m_entitiesByIdMutex);
1871-
1872-
for (auto object : data->objectIds)
18731871
{
1874-
if (!m_entitiesById[object].expired())
1872+
std::shared_lock<std::shared_mutex> entityListLock(m_entitiesByIdMutex);
1873+
1874+
for (auto object : data->objectIds)
18751875
{
1876-
used++;
1876+
if (!m_entitiesById[object].expired())
1877+
{
1878+
used++;
1879+
}
18771880
}
18781881
}
18791882

0 commit comments

Comments
 (0)