Feature/fetch comments exponential retries #153
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Timeout for fetching comments was set to 5 seconds, which on a slowish connection sometimes lead to a
timeout error (context deadline exceeded) when entering comment section mode.
I have only encountered this on stories with a large amount of comments. I believe the timeout occurs because the function attempts to fetch all comments associated with the story at once, which can be too much for slower connections or stories with a lot of comments.
This PR adds retry logic with exponential backoff and random jitter to the FetchComments function to handle timeouts more gracefully. (5s, 10s, 15s) It retries the request with increasing delays if the server is slow to respond. If all retries fail, an error gets logged. Of course this can be seen as a local fix, maybe something larger is needed in the future in order to achieve a more comprehensive solution to error handling of this kind. At least it seems to have fixed the timeouts for me, and I have not seen it posted elsewhere.