[MODULES-195] Avoid infinite loop when iterating over modules.