Current Behavior
The Do function returns the context timeout error when the context times out, which obscures the actual error that caused the retries to fail.
Desired Behavior
When the context times out,Do should return the last error encountered during the retry attempts, rather than the context timeout error. This will provide more meaningful information about the root cause of the failure.
Proposed Solution
Modify the Do function to store the last non-context error encountered and return it if the context times out.
This is possibly debatable behavior so definitely up for discussion :)