Skip to content

Commit

Permalink
fix(installer): Retry connection reset by peer network errors (#31115)
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteFoy authored Nov 15, 2024
1 parent de46c0a commit 0aef524
Showing 1 changed file with 17 additions and 2 deletions.
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

0 comments on commit 0aef524

Please sign in to comment.