fix #29511
fix #29421
dont remove elements from container while iterating