Skip to content

Commit

Permalink
Detect broken writes.
Browse files Browse the repository at this point in the history
No-Issue

Signed-off-by: James Tanner <[email protected]>
  • Loading branch information
jctanner committed Sep 10, 2023
1 parent 5da7170 commit ec98bfb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions profiles/insights/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ func isUseOfClosedNetworkConnection(err error) bool {
return strings.Contains(err.Error(), "use of closed network connection")
}

func isWriteBrokenPipe(err error) bool {
return strings.Contains(err.Error(), "write: broken pipe")
}

func retryHTTPRequest(client *http.Client, req *http.Request, maxRetries int) (*http.Response, error) {
for retry := 0; retry < maxRetries; retry++ {
resp, err := client.Do(req)
Expand All @@ -246,6 +250,11 @@ func retryHTTPRequest(client *http.Client, req *http.Request, maxRetries int) (*
time.Sleep(1 * time.Second) // Wait before retrying
continue
}
if isWriteBrokenPipe(err) {
fmt.Printf("Retry attempt %d: write broken pipe\n", retry+1)
time.Sleep(1 * time.Second) // Wait before retrying
continue
}

return nil, err
}
Expand Down

0 comments on commit ec98bfb

Please sign in to comment.