Merge pull request #28229 from darrenstahlmsft/FixUnexpectedResult

Fix failure to get containers when deleting a layer
This commit is contained in:
Tõnis Tiigi 2016-11-10 17:10:05 -08:00 committed by GitHub
commit d54f4472fd
3 changed files with 29 additions and 5 deletions

View file

@ -17,6 +17,7 @@ import (
"strings"
"sync"
"syscall"
"time"
"unsafe"
"github.com/Microsoft/go-winio"
@ -260,10 +261,29 @@ func (d *Driver) Remove(id string) error {
return err
}
// Get and terminate any template VMs that are currently using the layer
computeSystems, err := hcsshim.GetContainers(hcsshim.ComputeSystemQuery{})
if err != nil {
return err
// This retry loop is due to a bug in Windows (Internal bug #9432268)
// if GetContainers fails with ErrVmcomputeOperationInvalidState
// it is a transient error. Retry until it succeeds.
var computeSystems []hcsshim.ContainerProperties
retryCount := 0
for {
// Get and terminate any template VMs that are currently using the layer
computeSystems, err = hcsshim.GetContainers(hcsshim.ComputeSystemQuery{})
if err != nil {
if err == hcsshim.ErrVmcomputeOperationInvalidState {
if retryCount >= 5 {
// If we are unable to get the list of containers
// go ahead and attempt to delete the layer anyway
// as it will most likely work.
break
}
retryCount++
time.Sleep(2 * time.Second)
continue
}
return err
}
break
}
for _, computeSystem := range computeSystems {

View file

@ -1,6 +1,6 @@
# the following lines are in sorted order, FYI
github.com/Azure/go-ansiterm 388960b655244e76e24c75f48631564eaefade62
github.com/Microsoft/hcsshim v0.5.7
github.com/Microsoft/hcsshim v0.5.8
github.com/Microsoft/go-winio v0.3.6
github.com/Sirupsen/logrus f76d643702a30fbffecdfe50831e11881c96ceb3 https://github.com/aaronlehmann/logrus
github.com/davecgh/go-spew 6d212800a42e8ab5c146b8ace3490ee17e5225f9

View file

@ -192,6 +192,10 @@ func GetContainers(q ComputeSystemQuery) ([]ContainerProperties, error) {
)
err = hcsEnumerateComputeSystems(query, &computeSystemsp, &resultp)
err = processHcsResult(err, resultp)
if err != nil {
return nil, err
}
if computeSystemsp == nil {
return nil, ErrUnexpectedValue
}