HSEARCH-1622 Improve error report for infinite depth loops and add test