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

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -1291,19 +1291,20 @@ 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
{
1297+
std::shared_lock<std::shared_mutex> lock(m_entitiesByIdMutex);
1298+
entity = m_entitiesById[set & 0xFFFF];
1299+
}
1300+
12991301
auto entityRef = entity.lock();
13001302

13011303
if (entityRef)
13021304
{
13031305
OnCloneRemove(entityRef);
13041306
}
13051307
}
1306-
}
13071308

13081309
{
13091310
std::unique_lock<std::shared_mutex> entityListLock(m_entityListMutex);
@@ -1867,6 +1868,7 @@ void ServerGameState::AttachToObject(fx::ServerInstanceBase* instance)
18671868
auto [data, lock] = GetClientData(this, client);
18681869
int used = 0;
18691870

1871+
{
18701872
std::shared_lock<std::shared_mutex> entityListLock(m_entitiesByIdMutex);
18711873

18721874
for (auto object : data->objectIds)
@@ -1876,6 +1878,7 @@ void ServerGameState::AttachToObject(fx::ServerInstanceBase* instance)
18761878
used++;
18771879
}
18781880
}
1881+
}
18791882

18801883
console::Printf("net", "%s^7: %d/%d object IDs used/sent (%.2f percent)\n", client->GetName(), used, data->objectIds.size(), (used / (float)data->objectIds.size()) * 100.0f);
18811884
});

0 commit comments

Comments
 (0)