HIVE-7527: fix infinite loop