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

fix(installer): Retry connection reset by peer network errors #31115

Merged
merged 3 commits into from
Nov 15, 2024
Merged
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
19 changes: 17 additions & 2 deletions pkg/fleet/internal/oci/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import (
"context"
"errors"
"fmt"
"net"
"net/http"
"net/url"
"os"
"runtime"
"strconv"
"strings"
"syscall"
"time"

"github.com/awslabs/amazon-ecr-credential-helper/ecr-login"
Expand Down Expand Up @@ -320,10 +323,10 @@ func (d *DownloadedPackage) ExtractLayers(mediaType types.MediaType, dir string)
err = tar.Extract(uncompressedLayer, dir, layerMaxSize)
uncompressedLayer.Close()
if err != nil {
if !isStreamResetError(err) {
if !isStreamResetError(err) && !isConnectionResetByPeerError(err) {
return fmt.Errorf("could not extract layer: %w", err)
}
log.Warnf("stream error while extracting layer, retrying")
log.Warnf("network error while extracting layer, retrying")
// Clean up the directory before retrying to avoid partial extraction
err = tar.Clean(dir)
if err != nil {
Expand Down Expand Up @@ -381,6 +384,18 @@ func isStreamResetError(err error) bool {
return false
}

// isConnectionResetByPeer returns true if the error is a connection reset by peer error
func isConnectionResetByPeerError(err error) bool {
if netErr, ok := err.(*net.OpError); ok {
if syscallErr, ok := netErr.Err.(*os.SyscallError); ok {
if errno, ok := syscallErr.Err.(syscall.Errno); ok {
return errno == syscall.ECONNRESET
}
}
}
return false
}

type usernamePasswordKeychain struct {
username string
password string
Expand Down
Loading