VE-1560: Fix for endless loop

More information here: https://gerrit.wikimedia.org/r/#/c/163273/

https://wikia-inc.atlassian.net/browse/VE-1560