Skip to content

Commit

Permalink
Add timeout on needsTransfer function
Browse files Browse the repository at this point in the history
needsTransfer requires a network connection as it tries to get the digest of the image it is verifying. When running `TestOffline/group/crio`, LoadImages takes 6m30s to complete because it's waiting for i/o timeout. With this timeout, LoadImages takes ~45 seconds when running that integratin test.
  • Loading branch information
Priya Wadhwa committed Mar 24, 2020
1 parent abf35cf commit 39b08c9
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion pkg/minikube/machine/cache_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ func LoadImages(cc *config.ClusterConfig, runner command.Runner, images []string
for _, image := range images {
image := image
g.Go(func() error {
err := needsTransfer(imgClient, image, cr)
// Put a ten second limit on deciding if an image needs transfer
// because it takes much less than that time to just transfer the image.
// This is needed because if running in offline mode, we can spend minutes here
// waiting for i/o timeout.
err := timedNeedsTransfer(imgClient, image, cr, 10*time.Second)
if err == nil {
return nil
}
Expand All @@ -107,6 +111,28 @@ func LoadImages(cc *config.ClusterConfig, runner command.Runner, images []string
return nil
}

func timedNeedsTransfer(imgClient *client.Client, imgName string, cr cruntime.Manager, t time.Duration) error {
timeout := make(chan bool, 1)
go func() {
time.Sleep(t)
timeout <- true
}()

transferFinished := make(chan bool, 1)
var err error
go func() {
err = needsTransfer(imgClient, imgName, cr)
transferFinished <- true
}()

select {
case <-transferFinished:
return err
case <-timeout:
return fmt.Errorf("create host timed out in %f seconds", t.Seconds())
}
}

// needsTransfer returns an error if an image needs to be retransfered
func needsTransfer(imgClient *client.Client, imgName string, cr cruntime.Manager) error {
imgDgst := "" // for instance sha256:7c92a2c6bbcb6b6beff92d0a940779769c2477b807c202954c537e2e0deb9bed
Expand Down

0 comments on commit 39b08c9

Please sign in to comment.