Merge pull request #502 from mr-salty/fix-max-retry-exception

Prevent an exception with large num_retries.