提交 091059b8 编写于 作者: P Priya Wadhwa

Add timeout on needsTransfer function

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.
上级 abf35cfb
......@@ -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
}
......@@ -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("needs transfer 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册