Removing the call to Shutdown from within Signal in order to rely on waitExit handling the exit of the process.
Signed-off-by: Stefan J. Wernli <swernli@microsoft.com>
| ... | ... |
@@ -54,10 +54,7 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
|
| 54 | 54 |
"exitCode": strconv.Itoa(int(e.ExitCode)), |
| 55 | 55 |
} |
| 56 | 56 |
daemon.LogContainerEventWithAttributes(c, "die", attributes) |
| 57 |
- if err := c.ToDisk(); err != nil {
|
|
| 58 |
- return err |
|
| 59 |
- } |
|
| 60 |
- return daemon.postRunProcessing(c, e) |
|
| 57 |
+ return c.ToDisk() |
|
| 61 | 58 |
case libcontainerd.StateExitProcess: |
| 62 | 59 |
c.Lock() |
| 63 | 60 |
defer c.Unlock() |
| ... | ... |
@@ -344,6 +344,8 @@ func (clnt *client) Signal(containerID string, sig int) error {
|
| 344 | 344 |
return err |
| 345 | 345 |
} |
| 346 | 346 |
|
| 347 |
+ cont.manualStopRequested = true |
|
| 348 |
+ |
|
| 347 | 349 |
logrus.Debugf("lcd: Signal() containerID=%s sig=%d pid=%d", containerID, sig, cont.systemPid)
|
| 348 | 350 |
context := fmt.Sprintf("Signal: sig=%d pid=%d", sig, cont.systemPid)
|
| 349 | 351 |
|
| ... | ... |
@@ -352,7 +354,6 @@ func (clnt *client) Signal(containerID string, sig int) error {
|
| 352 | 352 |
if err := hcsshim.TerminateComputeSystem(containerID, hcsshim.TimeoutInfinite, context); err != nil {
|
| 353 | 353 |
logrus.Errorf("Failed to terminate %s - %q", containerID, err)
|
| 354 | 354 |
} |
| 355 |
- |
|
| 356 | 355 |
} else {
|
| 357 | 356 |
// Terminate Process |
| 358 | 357 |
if err = hcsshim.TerminateProcessInComputeSystem(containerID, cont.systemPid); err != nil {
|
| ... | ... |
@@ -360,24 +361,8 @@ func (clnt *client) Signal(containerID string, sig int) error {
|
| 360 | 360 |
// Ignore errors |
| 361 | 361 |
err = nil |
| 362 | 362 |
} |
| 363 |
- |
|
| 364 |
- // Shutdown the compute system |
|
| 365 |
- const shutdownTimeout = 5 * 60 * 1000 // 5 minutes |
|
| 366 |
- if err := hcsshim.ShutdownComputeSystem(containerID, shutdownTimeout, context); err != nil {
|
|
| 367 |
- if herr, ok := err.(*hcsshim.HcsError); !ok || |
|
| 368 |
- (herr.Err != hcsshim.ERROR_SHUTDOWN_IN_PROGRESS && |
|
| 369 |
- herr.Err != ErrorBadPathname && |
|
| 370 |
- herr.Err != syscall.ERROR_PATH_NOT_FOUND) {
|
|
| 371 |
- logrus.Debugf("signal - error from ShutdownComputeSystem %v on %s. Calling TerminateComputeSystem", err, containerID)
|
|
| 372 |
- if err := hcsshim.TerminateComputeSystem(containerID, shutdownTimeout, "signal"); err != nil {
|
|
| 373 |
- logrus.Debugf("signal - ignoring error from TerminateComputeSystem on %s %v", containerID, err)
|
|
| 374 |
- } else {
|
|
| 375 |
- logrus.Debugf("Successful TerminateComputeSystem after failed ShutdownComputeSystem on %s during signal %v", containerID, sig)
|
|
| 376 |
- } |
|
| 377 |
- } |
|
| 378 |
- logrus.Errorf("Failed to shutdown %s - %q", containerID, err)
|
|
| 379 |
- } |
|
| 380 | 363 |
} |
| 364 |
+ |
|
| 381 | 365 |
return nil |
| 382 | 366 |
} |
| 383 | 367 |
|
| ... | ... |
@@ -20,6 +20,8 @@ type container struct {
|
| 20 | 20 |
// but can be called from the RestartManager context which does not |
| 21 | 21 |
// otherwise have access to the Spec |
| 22 | 22 |
ociSpec Spec |
| 23 |
+ |
|
| 24 |
+ manualStopRequested bool |
|
| 23 | 25 |
} |
| 24 | 26 |
|
| 25 | 27 |
func (ctr *container) newProcess(friendlyName string) *process {
|
| ... | ... |
@@ -163,11 +165,10 @@ func (ctr *container) waitExit(pid uint32, processFriendlyName string, isFirstPr |
| 163 | 163 |
// But it could have been an exec'd process which exited |
| 164 | 164 |
if !isFirstProcessToStart {
|
| 165 | 165 |
si.State = StateExitProcess |
| 166 |
- } |
|
| 166 |
+ } else {
|
|
| 167 |
+ // Since this is the init process, always call into vmcompute.dll to |
|
| 168 |
+ // shutdown the container after we have completed. |
|
| 167 | 169 |
|
| 168 |
- // If this is the init process, always call into vmcompute.dll to |
|
| 169 |
- // shutdown the container after we have completed. |
|
| 170 |
- if isFirstProcessToStart {
|
|
| 171 | 170 |
propertyCheckFlag := 1 // Include update pending check. |
| 172 | 171 |
csProperties, err := hcsshim.GetComputeSystemProperties(ctr.containerID, uint32(propertyCheckFlag)) |
| 173 | 172 |
if err != nil {
|
| ... | ... |
@@ -196,7 +197,7 @@ func (ctr *container) waitExit(pid uint32, processFriendlyName string, isFirstPr |
| 196 | 196 |
logrus.Debugf("Completed shutting down container %s", ctr.containerID)
|
| 197 | 197 |
} |
| 198 | 198 |
|
| 199 |
- if si.State == StateExit && ctr.restartManager != nil {
|
|
| 199 |
+ if !ctr.manualStopRequested && ctr.restartManager != nil {
|
|
| 200 | 200 |
restart, wait, err := ctr.restartManager.ShouldRestart(uint32(exitCode), false, time.Since(ctr.startedAt)) |
| 201 | 201 |
if err != nil {
|
| 202 | 202 |
logrus.Error(err) |