fix: prevent infinite recursion in FlagManager.clearFlags - #1777
Merged
Conversation
Split out of #1677 (piece 4 of 8). If a FlagExpireTrigger-driven skill adds a new flag to an entity while FlagManager.clearFlags() is clearing that same entity's flags, the new flag re-creates a FlagData entry, and removing it during the same clear pass re-enters clearFlags() for that entity, recursing indefinitely (observed on player death, where clearing flags can trigger skills that re-flag the dying entity). Guard clearFlags() with a per-entity "currently clearing" set so a reentrant call for the same entity is a no-op instead of recursing.
This was referenced Jul 21, 2026
Open
Reproduces the infinite-recursion scenario the guard fixes: a FlagExpireTrigger-driven skill reacting to FlagExpireEvent by adding a new flag to the same entity while clearFlags() is still unwinding for that entity. Without the clearingEntities guard, this recurses through clear() -> removeFlag() -> (synchronous event) -> addFlag() -> clearFlags() until the stack overflows; with it, the reentrant call is a no-op and the newly-added flag survives.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split out of #1677 (piece 4 of 8 — see that PR for the full breakdown).
What
If a
FlagExpireTrigger-driven skill adds a new flag to an entity whileFlagManager.clearFlags()is clearing that same entity's flags, the new flag re-creates aFlagDataentry, and removing it during the same clear pass re-entersclearFlags()for that entity — recursing indefinitely. This was reportedly observed on player death, where clearing flags can trigger skills that re-flag the dying entity.Guards
clearFlags()with a per-entity "currently clearing" set, so a reentrant call for the same entity becomes a no-op instead of recursing.Why split out separately
Small, standalone bug fix isolated to one class — easy to review and test on its own (repro: a flag-expire-triggered skill that re-adds a flag to the same entity during
clearFlags, e.g. on death).Testing
Could not build locally (private Maven repo unreachable in this sandbox). Needs manual/CI verification, especially a repro of the original infinite-recursion scenario.
Generated by Claude Code