Skip to content

Commit

Permalink
Improve FlushEntities() error logs (#5427)
Browse files Browse the repository at this point in the history
* Improve FlushEntities() error logs

* log count before flush
  • Loading branch information
ElectroJr authored Sep 16, 2024
1 parent 4949b34 commit f5c1d87
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Robust.Shared/GameObjects/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,23 @@ public bool Deleted([NotNullWhen(false)] EntityUid? uid)
/// </summary>
public virtual void FlushEntities()
{
_sawmill.Info($"Flushing entities. Entity count: {Entities.Count}");
BeforeEntityFlush?.Invoke();
FlushEntitiesInternal();

if (Entities.Count != 0)
_sawmill.Error("Failed to flush all entities");
{
_sawmill.Error($"Failed to flush all entities. Entity count: {Entities.Count}");
// Dump entity info, but avoid dumping ~50k errors if for whatever reason we failed to delete almost all entities.
// Using 512 as the limit, in case the problem entities are related to player counts on high-pop servers.
if (Entities.Count < 512)
{
foreach (var uid in Entities)
{
_sawmill.Error($"Entity exists after flush: {ToPrettyString(uid)}");
}
}
}

#if EXCEPTION_TOLERANCE
// Attempt to flush entities a second time, just in case something somehow caused an entity to be spawned
Expand All @@ -705,7 +717,7 @@ public virtual void FlushEntities()
#endif

if (Entities.Count != 0)
throw new Exception("Failed to flush all entities");
throw new Exception($"Failed to flush all entities. Entity count: {Entities.Count}");

AfterEntityFlush?.Invoke();
}
Expand Down

0 comments on commit f5c1d87

Please sign in to comment.