Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added simple retry logic for failed post requests (#560) #561

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

## Added
* The splunk span sink can be configured with a sample rate for non-indicator spans with the `splunk_span_sample_rate` setting. Thanks, [aditya](https://github.com/chimeracoder)!
* Added retry logic to POST requests if they fail due to IO exceptions (such as timeouts and connection resets). Requests now are tried four times; One initially and another three if the 1st request fails. Thanks, [volfco](https://github.com/volfco)!

# 8.0.0, 2018-09-20

Expand Down
14 changes: 14 additions & 0 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,21 @@ func PostHelper(ctx context.Context, httpClient *http.Client, tc *trace.Client,
req = req.WithContext(httptrace.WithClientTrace(req.Context(), hct.getClientTrace()))
defer hct.finishSpan()

retry := 3
resp, err := httpClient.Do(req)

// If our initial request fails, we want to try again
if err != nil {
for i := 0; i < retry; i++ {
resp, err = httpClient.Do(req)
if err == nil {
break
}
// 50ms
time.Sleep(50 * time.Millisecond)
}
}

if err != nil {
if urlErr, ok := err.(*url.Error); ok {
// if the error has the url in it, then retrieve the inner error
Expand Down