Skip to content
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
2 changes: 1 addition & 1 deletion cmd/containerd-shim-lcow-v2/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"

runhcsopts "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
"github.com/Microsoft/hcsshim/internal/hcs"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/Microsoft/hcsshim/internal/memory"
"github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/internal/shim"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/Microsoft/hcsshim/internal/controller/pod"
"github.com/Microsoft/hcsshim/internal/controller/process"
"github.com/Microsoft/hcsshim/internal/controller/vm"
"github.com/Microsoft/hcsshim/internal/hcs"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/logfields"
"github.com/Microsoft/hcsshim/internal/memory"
Expand Down
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/Microsoft/hcsshim/internal/hcs"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/Microsoft/hcsshim/internal/memory"
"github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/internal/winapi"
Expand Down
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/exec_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/Microsoft/hcsshim/internal/cmd"
"github.com/Microsoft/hcsshim/internal/cow"
"github.com/Microsoft/hcsshim/internal/hcs"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/oc"
"github.com/Microsoft/hcsshim/internal/protocol/guestresource"
Expand Down
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
"github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats"
"github.com/Microsoft/hcsshim/internal/hcs"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/Microsoft/hcsshim/internal/shimdiag"
"github.com/Microsoft/hcsshim/pkg/ctrdtaskapi"
task "github.com/containerd/containerd/api/runtime/task/v2"
Expand Down
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/task_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (
"github.com/Microsoft/hcsshim/internal/cmd"
"github.com/Microsoft/hcsshim/internal/cow"
"github.com/Microsoft/hcsshim/internal/guestpath"
"github.com/Microsoft/hcsshim/internal/hcs"
"github.com/Microsoft/hcsshim/internal/hcs/resourcepaths"
"github.com/Microsoft/hcsshim/internal/hcs/schema1"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/Microsoft/hcsshim/internal/hcsoci"
"github.com/Microsoft/hcsshim/internal/jobcontainers"
"github.com/Microsoft/hcsshim/internal/layers"
Expand Down
58 changes: 29 additions & 29 deletions internal/computecore/computecore.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"
"unsafe"

"github.com/sirupsen/logrus"
"go.opencensus.io/trace"

"github.com/Microsoft/hcsshim/internal/interop"
Expand Down Expand Up @@ -94,39 +93,40 @@ import (
// errVmcomputeOperationPending is an error encountered when the operation is being completed asynchronously
const errVmcomputeOperationPending = syscall.Errno(0xC0370103)

// execute runs f synchronously to completion. ctx and timeout are
// watchdogs only: each emits a one-shot warning when exceeded and the
// wait continues until f returns.
//
// Callers of the wrapping HCS API typically release the handles they
// passed in via defer once the call returns. Abandoning f mid-flight
// would let those defers tear down handles the syscall is still using,
// which has been observed to crash the shim with EXCEPTION_ACCESS_VIOLATION
// inside computecore.dll. Long-running operations should be bounded via
// HcsCancelOperation rather than by returning early.
func execute(ctx gcontext.Context, timeout time.Duration, f func() error) error {
now := time.Now()
if timeout > 0 {
var cancel gcontext.CancelFunc
ctx, cancel = gcontext.WithTimeout(ctx, timeout)
defer cancel()
}
done := make(chan error, 1)
go func() { done <- f() }()

deadline, ok := ctx.Deadline()
trueTimeout := timeout
if ok {
trueTimeout = deadline.Sub(now)
log.G(ctx).WithFields(logrus.Fields{
logfields.Timeout: trueTimeout,
"desiredTimeout": timeout,
}).Trace("Executing syscall with deadline")
var watcher <-chan time.Time
if timeout > 0 {
t := time.NewTimer(timeout)
defer t.Stop()
watcher = t.C
}

done := make(chan error, 1)
go func() {
done <- f()
}()
select {
case <-ctx.Done():
if ctx.Err() == gcontext.DeadlineExceeded {
log.G(ctx).WithField(logfields.Timeout, trueTimeout).
Warning("Syscall did not complete within operation timeout. This may indicate a platform issue. " +
"If it appears to be making no forward progress, obtain the stacks and see if there is a syscall " +
"stuck in the platform API for a significant length of time.")
for {
select {
case err := <-done:
return err
case <-watcher:
log.G(ctx).WithField(logfields.Timeout, timeout).
Warning("HCS syscall exceeded timeout; still waiting to avoid use-after-free in computecore.dll")
watcher = nil
case <-ctx.Done():
log.G(ctx).WithError(ctx.Err()).
Warning("HCS syscall context canceled; still waiting to avoid use-after-free in computecore.dll")
ctx = gcontext.WithoutCancel(ctx)
}
return ctx.Err()
case err := <-done:
return err
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/device/plan9/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/Microsoft/go-winio/pkg/guid"
"github.com/Microsoft/hcsshim/internal/controller/device/plan9/mount"
"github.com/Microsoft/hcsshim/internal/controller/device/plan9/share"
"github.com/Microsoft/hcsshim/internal/hcs"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/logfields"
"github.com/sirupsen/logrus"
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/linuxcontainer/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/Microsoft/hcsshim/internal/controller/linuxcontainer/mocks"
"github.com/Microsoft/hcsshim/internal/controller/process"
"github.com/Microsoft/hcsshim/internal/gcs"
"github.com/Microsoft/hcsshim/internal/hcs"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/Microsoft/hcsshim/internal/protocol/guestresource"
"github.com/Microsoft/hcsshim/internal/signals"

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/network/network_lcow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/Microsoft/hcsshim/internal/controller/network/mocks"
"github.com/Microsoft/hcsshim/internal/gcs"
"github.com/Microsoft/hcsshim/internal/guest/prot"
"github.com/Microsoft/hcsshim/internal/hcs"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/Microsoft/hcsshim/internal/protocol/guestresource"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/network/network_wcow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/Microsoft/hcsshim/hcn"
"github.com/Microsoft/hcsshim/internal/controller/network/mocks"
"github.com/Microsoft/hcsshim/internal/gcs"
"github.com/Microsoft/hcsshim/internal/hcs"
"github.com/Microsoft/hcsshim/internal/hcs/schema1"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/Microsoft/hcsshim/internal/protocol/guestrequest"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/Microsoft/hcsshim/internal/cmd"
"github.com/Microsoft/hcsshim/internal/cow"
"github.com/Microsoft/hcsshim/internal/hcs"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/logfields"
eventstypes "github.com/containerd/containerd/api/events"
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"go.uber.org/mock/gomock"

"github.com/Microsoft/hcsshim/internal/controller/process/mocks"
"github.com/Microsoft/hcsshim/internal/hcs"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion internal/cpugroup/cpugroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"fmt"
"strings"

"github.com/Microsoft/hcsshim/internal/hcs"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/pkg/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"errors"
"fmt"

"github.com/Microsoft/hcsshim/internal/hcs"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
hcs "github.com/Microsoft/hcsshim/internal/hcs/v2"
"github.com/Microsoft/hcsshim/internal/log"
)

Expand Down
8 changes: 6 additions & 2 deletions internal/gcs/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ func (p *Process) ExitCode() (_ int, err error) {
return -1, errors.New("process not exited")
}
if err := p.waitCall.Err(); err != nil {
return -1, err
var rerr *rpcError
if !errors.As(err, &rerr) || uint32(rerr.result) != hrNotFound {
return -1, err
}
}
return int(p.waitResp.ExitCode), nil
}
Expand Down Expand Up @@ -274,7 +277,8 @@ func (p *Process) Stdio() (stdin io.Writer, stdout, stderr io.Reader) {
// Wait waits for the process (or guest connection) to terminate.
func (p *Process) Wait() error {
p.waitCall.Wait()
return p.waitCall.Err()
_, err := p.ExitCode()
return err
}

func (p *Process) waitBackground() {
Expand Down
Loading
Loading