Fix infinite looping

* Use the retry_submit flag to control the looping. Exit
the loop when this flag is flipped to False