moby/daemon
John Howard 8c52560ea4 Windows: Pass back system errors on container exit
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
```
2018-02-22 08:53:43 -08:00
..
caps Add canonical import comment 2018-02-05 16:51:57 -05:00
cluster Add canonical import comment 2018-02-05 16:51:57 -05:00
config Add canonical import comment 2018-02-05 16:51:57 -05:00
discovery Add canonical import comment 2018-02-05 16:51:57 -05:00
events Add canonical import comment 2018-02-05 16:51:57 -05:00
exec Add canonical import comment 2018-02-05 16:51:57 -05:00
graphdriver Add canonical import comment 2018-02-05 16:51:57 -05:00
initlayer Add canonical import comment 2018-02-05 16:51:57 -05:00
links Add canonical import comment 2018-02-05 16:51:57 -05:00
listeners Add canonical import comment 2018-02-05 16:51:57 -05:00
logger Merge pull request #36220 from dnephin/support-proxy-in-splunk-driver 2018-02-08 15:32:19 +01:00
names Add canonical import comment 2018-02-05 16:51:57 -05:00
network Add canonical import comment 2018-02-05 16:51:57 -05:00
stats Add canonical import comment 2018-02-05 16:51:57 -05:00
testdata Remove libtrust dep from api 2017-09-06 12:05:19 -04:00
apparmor_default.go Add canonical import comment 2018-02-05 16:51:57 -05:00
apparmor_default_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
archive.go Add canonical import comment 2018-02-05 16:51:57 -05:00
archive_tarcopyoptions.go Add canonical import comment 2018-02-05 16:51:57 -05:00
archive_tarcopyoptions_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
archive_tarcopyoptions_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
archive_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
archive_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
attach.go Add canonical import comment 2018-02-05 16:51:57 -05:00
auth.go Add canonical import comment 2018-02-05 16:51:57 -05:00
bindmount_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
build.go Add canonical import comment 2018-02-05 16:51:57 -05:00
cache.go Add canonical import comment 2018-02-05 16:51:57 -05:00
changes.go Add canonical import comment 2018-02-05 16:51:57 -05:00
checkpoint.go Add canonical import comment 2018-02-05 16:51:57 -05:00
cluster.go Add canonical import comment 2018-02-05 16:51:57 -05:00
commit.go Merge pull request #36224 from dnephin/refactor-commit 2018-02-08 21:02:30 +09:00
configs.go Add canonical import comment 2018-02-05 16:51:57 -05:00
configs_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
configs_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
configs_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
container.go Add canonical import comment 2018-02-05 16:51:57 -05:00
container_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
container_operations.go Add canonical import comment 2018-02-05 16:51:57 -05:00
container_operations_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
container_operations_windows.go Merge pull request #36194 from dnephin/add-canonical-import 2018-02-07 13:06:45 -08:00
container_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
create.go Add canonical import comment 2018-02-05 16:51:57 -05:00
create_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
create_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
create_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
daemon.go Add canonical import comment 2018-02-05 16:51:57 -05:00
daemon_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
daemon_linux_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
daemon_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
daemon_unix.go Merge pull request #36194 from dnephin/add-canonical-import 2018-02-07 13:06:45 -08:00
daemon_unix_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
daemon_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
daemon_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
daemon_windows_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
debugtrap_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
debugtrap_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
debugtrap_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
delete.go Add canonical import comment 2018-02-05 16:51:57 -05:00
delete_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
dependency.go Add canonical import comment 2018-02-05 16:51:57 -05:00
disk_usage.go Add canonical import comment 2018-02-05 16:51:57 -05:00
errors.go Add canonical import comment 2018-02-05 16:51:57 -05:00
events.go Add canonical import comment 2018-02-05 16:51:57 -05:00
events_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
exec.go Add canonical import comment 2018-02-05 16:51:57 -05:00
exec_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
exec_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
export.go Add canonical import comment 2018-02-05 16:51:57 -05:00
getsize_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
health.go Add canonical import comment 2018-02-05 16:51:57 -05:00
health_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
image.go Add canonical import comment 2018-02-05 16:51:57 -05:00
image_delete.go Add canonical import comment 2018-02-05 16:51:57 -05:00
image_exporter.go Add canonical import comment 2018-02-05 16:51:57 -05:00
image_history.go Add canonical import comment 2018-02-05 16:51:57 -05:00
image_inspect.go Add canonical import comment 2018-02-05 16:51:57 -05:00
image_pull.go Add canonical import comment 2018-02-05 16:51:57 -05:00
image_push.go Add canonical import comment 2018-02-05 16:51:57 -05:00
image_tag.go Add canonical import comment 2018-02-05 16:51:57 -05:00
images.go Add canonical import comment 2018-02-05 16:51:57 -05:00
import.go Add canonical import comment 2018-02-05 16:51:57 -05:00
info.go Add canonical import comment 2018-02-05 16:51:57 -05:00
info_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
info_unix_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
info_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
inspect.go Add canonical import comment 2018-02-05 16:51:57 -05:00
inspect_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
inspect_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
keys.go Add canonical import comment 2018-02-05 16:51:57 -05:00
keys_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
kill.go Add canonical import comment 2018-02-05 16:51:57 -05:00
links.go Add canonical import comment 2018-02-05 16:51:57 -05:00
list.go Add canonical import comment 2018-02-05 16:51:57 -05:00
list_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
list_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
logdrivers_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
logdrivers_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
logs.go Add canonical import comment 2018-02-05 16:51:57 -05:00
logs_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
metrics.go Add canonical import comment 2018-02-05 16:51:57 -05:00
metrics_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
metrics_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
monitor.go Windows: Pass back system errors on container exit 2018-02-22 08:53:43 -08:00
monitor_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
monitor_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
mounts.go Add canonical import comment 2018-02-05 16:51:57 -05:00
names.go Add canonical import comment 2018-02-05 16:51:57 -05:00
network.go Add canonical import comment 2018-02-05 16:51:57 -05:00
oci_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
oci_linux_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
oci_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
pause.go Add canonical import comment 2018-02-05 16:51:57 -05:00
prune.go Add canonical import comment 2018-02-05 16:51:57 -05:00
reload.go Add canonical import comment 2018-02-05 16:51:57 -05:00
reload_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
reload_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
reload_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
rename.go Add canonical import comment 2018-02-05 16:51:57 -05:00
resize.go Add canonical import comment 2018-02-05 16:51:57 -05:00
restart.go Add canonical import comment 2018-02-05 16:51:57 -05:00
search.go Add canonical import comment 2018-02-05 16:51:57 -05:00
search_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
seccomp_disabled.go Add canonical import comment 2018-02-05 16:51:57 -05:00
seccomp_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
seccomp_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
secrets.go Add canonical import comment 2018-02-05 16:51:57 -05:00
secrets_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
secrets_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
secrets_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
selinux_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
selinux_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
start.go Add canonical import comment 2018-02-05 16:51:57 -05:00
start_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
start_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
stats.go Add canonical import comment 2018-02-05 16:51:57 -05:00
stats_collector.go Add canonical import comment 2018-02-05 16:51:57 -05:00
stats_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
stats_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
stop.go Add canonical import comment 2018-02-05 16:51:57 -05:00
top_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
top_unix_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
top_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
trustkey.go Add canonical import comment 2018-02-05 16:51:57 -05:00
trustkey_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
unpause.go Add canonical import comment 2018-02-05 16:51:57 -05:00
update.go Add canonical import comment 2018-02-05 16:51:57 -05:00
update_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
update_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
volumes.go Add canonical import comment 2018-02-05 16:51:57 -05:00
volumes_unit_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
volumes_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
volumes_unix_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
volumes_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
wait.go Add canonical import comment 2018-02-05 16:51:57 -05:00
workdir.go Add canonical import comment 2018-02-05 16:51:57 -05:00