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

[release/0.9] Add ErrInvalidHandle and fix list stats #1277

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion cmd/containerd-shim-runhcs-v1/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ func isStatsNotFound(err error) bool {
hcs.IsNotExist(err) ||
hcs.IsOperationInvalidState(err) ||
gcs.IsNotExist(err) ||
hcs.IsAccessIsDenied(err)
hcs.IsAccessIsDenied(err) ||
hcs.IsErrorInvalidHandle(err)
}
6 changes: 5 additions & 1 deletion cmd/containerd-shim-runhcs-v1/task_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,13 @@ func hcsPropertiesToWindowsStats(props *hcsschema.Properties) *stats.Statistics_
func (ht *hcsTask) Stats(ctx context.Context) (*stats.Statistics, error) {
s := &stats.Statistics{}
props, err := ht.c.PropertiesV2(ctx, hcsschema.PTStatistics)
if err != nil && !isStatsNotFound(err) {
if err != nil {
if isStatsNotFound(err) {
return nil, errors.Wrapf(errdefs.ErrNotFound, "failed to fetch stats: %s", err)
}
return nil, err
}

if props != nil {
if ht.isWCOW {
s.Container = hcsPropertiesToWindowsStats(props)
Expand Down
12 changes: 12 additions & 0 deletions internal/hcs/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ var (

// ErrProcessAlreadyStopped is returned by hcs if the process we're trying to kill has already been stopped.
ErrProcessAlreadyStopped = syscall.Errno(0x8037011f)

// ErrInvalidHandle is an error that can be encountrered when querying the properties of a compute system when the handle to that
// compute system has already been closed.
ErrInvalidHandle = syscall.Errno(0x6)
)

type ErrorEvent struct {
Expand Down Expand Up @@ -252,6 +256,14 @@ func IsNotExist(err error) bool {
err == ErrElementNotFound
}

// IsErrorInvalidHandle checks whether the error is the result of an operation carried
// out on a handle that is invalid/closed. This error popped up while trying to query
// stats on a container in the process of being stopped.
func IsErrorInvalidHandle(err error) bool {
err = getInnerError(err)
return err == ErrInvalidHandle
}

// IsAlreadyClosed checks if an error is caused by the Container or Process having been
// already closed by a call to the Close() method.
func IsAlreadyClosed(err error) bool {
Expand Down
12 changes: 12 additions & 0 deletions test/vendor/github.com/Microsoft/hcsshim/internal/hcs/errors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.