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

Retry wsarecv: An existing connection was forcibly closed by the remote host. #2916

Merged
merged 4 commits into from
Mar 2, 2025
Merged
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
10 changes: 9 additions & 1 deletion ste/xferRetryHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (

var RetryStatusCodes RetryCodes

var platformRetryPolicy func(response *http.Response, err error) bool

func getShouldRetry() func(*http.Response, error) bool {
if len(RetryStatusCodes) == 0 {
return nil
Expand All @@ -48,7 +50,13 @@ func getShouldRetry() func(*http.Response, error) bool {
}
}
}
return false

// fall back to our platform retry policy
if platformRetryPolicy != nil {
return platformRetryPolicy(resp, err)
} else {
return false // If we have none, don't retry.
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions ste/xferRetryHelper_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package ste

import (
"errors"
"github.com/stretchr/testify/assert"
"net/http"
"runtime"
"syscall"
"testing"
)

Expand Down Expand Up @@ -38,6 +41,14 @@ func TestGetShouldRetry(t *testing.T) {
header["x-ms-error-code"] = []string{"ContainerBeingDeleted"}
response = &http.Response{Header: header, StatusCode: 409}
a.False(shouldRetry(response, nil))

if runtime.GOOS == "windows" {
rawErr := syscall.Errno(10054) // magic number, in reference to windows.WSAECONNRESET, preventing OS specific shenanigans
strErr := errors.New("wsarecv: An existing connection was forcibly closed by the remote host.")

a.True(shouldRetry(nil, rawErr))
a.True(shouldRetry(nil, strErr))
}
}

func TestGetErrorCode(t *testing.T) {
Expand Down
22 changes: 22 additions & 0 deletions ste/xferRetryHelper_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build windows

package ste

import (
"errors"
"golang.org/x/sys/windows"
"net/http"
"strings"
)

func init() {
platformRetryPolicy = func(response *http.Response, err error) bool {
// It's entirely possible something in between closed our connection.
if errors.Is(err, windows.WSAECONNRESET) || // Catch it in the idiomatic way
strings.Contains(strings.ToLower(err.Error()), "an existing connection was forcibly closed by the remote host.") { // But just in case something funny happened along the line, let's listen for the string we expect.
return true
}

return false
}
}
Loading