-
-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: crash when removing items during iteration with ContainerIterator #2901
Conversation
4ae2f7e
to
137c8fd
Compare
ef32935
to
56822e5
Compare
I've installed this on 100+ server that goes into infinite |
There is a server with 100+ users testing for over 5 days, and so far no issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and working.
d062854
to
4e5b724
Compare
c4245f5
to
0f25cff
Compare
185db07
to
a2514d3
Compare
925f1be
to
439b49b
Compare
Quality Gate passedIssues Measures |
Description
The enhancements to the ContainerIterator address critical issues related to deeply nested and cyclic container structures. By implementing cycle detection, traversal depth limitation, the iterator becomes a more reliable and efficient tool for managing complex container hierarchies. These improvements are essential for maintaining the system's performance and stability as it scales and evolves.
OBS: Added a talkaction that will make it easier to test (both counting items/subcontainers, which will call the getItems function, which internally calls the ContainerIterator). This will make it easier to know if the modification was done correctly.
Behaviour
Actual
Removing items from a container during iteration causes a crash due to invalidated iterators.
Example: During an event or action that removes items while iterating, the server crashes.
Expected
Items can be safely removed from a container during iteration without causing a crash.
The iteration continues correctly, and the application remains stable.
Type of change
How Has This Been Tested
We conducted tests to verify that the crash no longer occurs when items are removed during iteration:
Test A: Used a command (!container) that iterates over a player's backpack and removes items during iteration. Confirmed that no crash occurs and all items are removed safely.
Test the command before this implementation, it will crash. This can happen in various contexts, for example, during the reading of the "itemlist" in a loop, and the player removes an item from the container being read, it will cause a crash because it invalidates all iterators.
After implementing the fix, the crash will no longer occur with the command above, and it likely won't happen in other scenarios either.
NOTE: In the code, the "container->removeItem(item)" function will disrupt the iterator's count, but it will neither crash nor cause any errors. This happens because the iterator becomes unreliable when the container is modified during iteration. However, it effectively prevents a crash, which is our primary objective. If you want to test only the amount of items scanned, comment out the "removeItem.
Checklist
Fixes this crash:
crash-container-iterator.log