Try search repeatedly until success (rebase)

See: gh-3160

--rebase-from #3160