mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
8c52560ea4
Signed-off-by: John Howard <jhoward@microsoft.com> While debugging #32838, it was found (https://github.com/moby/moby/issues/32838#issuecomment-356005845) that the utility VM in some circumstances was crashing. Unfortunately, this was silently thrown away, and as far as the build step (also applies to docker run) was concerned, the exit code was zero and the error was thrown away. Windows containers operate differently to containers on Linux, and there can be legitimate system errors during container shutdown after the init process exits. This PR handles this and passes the error all the way back to the client, and correctly causes a build step running a container which hits a system error to fail, rather than blindly trying to keep going, assuming all is good, and get a subsequent failure on a commit. With this change, assuming an error occurs, here's an example of a failure which previous was reported as a commit error: ``` The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Install-WindowsFeature -Name Web-App-Dev ; Install-WindowsFeature -Name ADLDS; Install-WindowsFeature -Name Web-Mgmt-Compat; Install-WindowsFeature -Name Web-Mgmt-Service; Install-WindowsFeature -Name Web-Metabase; Install-WindowsFeature -Name Web-Lgcy-Scripting; Install-WindowsFeature -Name Web-WMI; Install-WindowsFeature -Name Web-WHC; Install-WindowsFeature -Name Web-Scripting-Tools; Install-WindowsFeature -Name Web-Net-Ext45; Install-WindowsFeature -Name Web-ASP; Install-WindowsFeature -Name Web-ISAPI-Ext; Install-WindowsFeature -Name Web-ISAPI-Filter; Install-WindowsFeature -Name Web-Default-Doc; Install-WindowsFeature -Name Web-Dir-Browsing; Install-WindowsFeature -Name Web-Http-Errors; Install-WindowsFeature -Name Web-Static-Content; Install-WindowsFeature -Name Web-Http-Redirect; Install-WindowsFeature -Name Web-DAV-Publishing; Install-WindowsFeature -Name Web-Health; Install-WindowsFeature -Name Web-Http-Logging; Install-WindowsFeature -Name Web-Custom-Logging; Install-WindowsFeature -Name Web-Log-Libraries; Install-WindowsFeature -Name Web-Request-Monitor; Install-WindowsFeature -Name Web-Http-Tracing; Install-WindowsFeature -Name Web-Stat-Compression; Install-WindowsFeature -Name Web-Dyn-Compression; Install-WindowsFeature -Name Web-Security; Install-WindowsFeature -Name Web-Windows-Auth; Install-WindowsFeature -Name Web-Basic-Auth; Install-WindowsFeature -Name Web-Url-Auth; Install-WindowsFeature -Name Web-WebSockets; Install-WindowsFeature -Name Web-AppInit; Install-WindowsFeature -Name NET-WCF-HTTP-Activation45; Install-WindowsFeature -Name NET-WCF-Pipe-Activation45; Install-WindowsFeature -Name NET-WCF-TCP-Activation45;' returned a non-zero code: 4294967295: container shutdown failed: container ba9c65054d42d4830fb25ef55e4ab3287550345aa1a2bb265df4e5bfcd79c78a encountered an error during WaitTimeout: failure in a Windows system call: The compute system exited unexpectedly. (0xc0370106) ``` Without this change, it would be incorrectly reported such as in this comment: https://github.com/moby/moby/issues/32838#issuecomment-309621097 ``` Step 3/8 : ADD buildtools C:/buildtools re-exec error: exit status 1: output: time="2017-06-20T11:37:38+10:00" level=error msg="hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) layerId=\\\\?\\C:\\ProgramData\\docker\\windowsfilter\\b41d28c95f98368b73fc192cb9205700e21 6691495c1f9ac79b9b04ec4923ea2 flavour=1 folder=C:\\Windows\\TEMP\\hcs232661915" hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) layerId=\\?\C:\ProgramData\docker\windowsfilter\b41d28c95f98368b73fc192cb9205700e216691495c1f9ac79b9b04ec4923ea2 flavour=1 folder=C:\Windows\TEMP\hcs232661915 ```
110 lines
4.1 KiB
Go
110 lines
4.1 KiB
Go
package libcontainerd // import "github.com/docker/docker/libcontainerd"
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/containerd/containerd"
|
|
"github.com/containerd/containerd/cio"
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
|
)
|
|
|
|
// EventType represents a possible event from libcontainerd
|
|
type EventType string
|
|
|
|
// Event constants used when reporting events
|
|
const (
|
|
EventUnknown EventType = "unknown"
|
|
EventExit EventType = "exit"
|
|
EventOOM EventType = "oom"
|
|
EventCreate EventType = "create"
|
|
EventStart EventType = "start"
|
|
EventExecAdded EventType = "exec-added"
|
|
EventExecStarted EventType = "exec-started"
|
|
EventPaused EventType = "paused"
|
|
EventResumed EventType = "resumed"
|
|
)
|
|
|
|
// Status represents the current status of a container
|
|
type Status string
|
|
|
|
// Possible container statuses
|
|
const (
|
|
// Running indicates the process is currently executing
|
|
StatusRunning Status = "running"
|
|
// Created indicates the process has been created within containerd but the
|
|
// user's defined process has not started
|
|
StatusCreated Status = "created"
|
|
// Stopped indicates that the process has ran and exited
|
|
StatusStopped Status = "stopped"
|
|
// Paused indicates that the process is currently paused
|
|
StatusPaused Status = "paused"
|
|
// Pausing indicates that the process is currently switching from a
|
|
// running state into a paused state
|
|
StatusPausing Status = "pausing"
|
|
// Unknown indicates that we could not determine the status from the runtime
|
|
StatusUnknown Status = "unknown"
|
|
)
|
|
|
|
// Remote on Linux defines the accesspoint to the containerd grpc API.
|
|
// Remote on Windows is largely an unimplemented interface as there is
|
|
// no remote containerd.
|
|
type Remote interface {
|
|
// Client returns a new Client instance connected with given Backend.
|
|
NewClient(namespace string, backend Backend) (Client, error)
|
|
// Cleanup stops containerd if it was started by libcontainerd.
|
|
// Note this is not used on Windows as there is no remote containerd.
|
|
Cleanup()
|
|
}
|
|
|
|
// RemoteOption allows to configure parameters of remotes.
|
|
// This is unused on Windows.
|
|
type RemoteOption interface {
|
|
Apply(Remote) error
|
|
}
|
|
|
|
// EventInfo contains the event info
|
|
type EventInfo struct {
|
|
ContainerID string
|
|
ProcessID string
|
|
Pid uint32
|
|
ExitCode uint32
|
|
ExitedAt time.Time
|
|
OOMKilled bool
|
|
// Windows Only field
|
|
UpdatePending bool
|
|
Error error
|
|
}
|
|
|
|
// Backend defines callbacks that the client of the library needs to implement.
|
|
type Backend interface {
|
|
ProcessEvent(containerID string, event EventType, ei EventInfo) error
|
|
}
|
|
|
|
// Client provides access to containerd features.
|
|
type Client interface {
|
|
Version(ctx context.Context) (containerd.Version, error)
|
|
|
|
Restore(ctx context.Context, containerID string, attachStdio StdioCallback) (alive bool, pid int, err error)
|
|
|
|
Create(ctx context.Context, containerID string, spec *specs.Spec, runtimeOptions interface{}) error
|
|
Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio StdioCallback) (pid int, err error)
|
|
SignalProcess(ctx context.Context, containerID, processID string, signal int) error
|
|
Exec(ctx context.Context, containerID, processID string, spec *specs.Process, withStdin bool, attachStdio StdioCallback) (int, error)
|
|
ResizeTerminal(ctx context.Context, containerID, processID string, width, height int) error
|
|
CloseStdin(ctx context.Context, containerID, processID string) error
|
|
Pause(ctx context.Context, containerID string) error
|
|
Resume(ctx context.Context, containerID string) error
|
|
Stats(ctx context.Context, containerID string) (*Stats, error)
|
|
ListPids(ctx context.Context, containerID string) ([]uint32, error)
|
|
Summary(ctx context.Context, containerID string) ([]Summary, error)
|
|
DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
|
|
Delete(ctx context.Context, containerID string) error
|
|
Status(ctx context.Context, containerID string) (Status, error)
|
|
|
|
UpdateResources(ctx context.Context, containerID string, resources *Resources) error
|
|
CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error
|
|
}
|
|
|
|
// StdioCallback is called to connect a container or process stdio.
|
|
type StdioCallback func(io *cio.DirectIO) (cio.IO, error)
|