From 6e6960c5399741c92060183fb39313b1e46c9865 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Fri, 13 Sep 2024 11:17:31 -0700 Subject: [PATCH] Run post-restore hook in the background. After restorer.restoreDone() returns successfully, the sandbox has been started and the application is running. The caller of restorer.restore() is the "runsc restore" command. Do not hang the "restore" command even after the sandbox has been restored. Do the post-restore work in a separate goroutine. If it fails, log a warning and kill the sandbox. PiperOrigin-RevId: 674366811 --- runsc/boot/restore.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/runsc/boot/restore.go b/runsc/boot/restore.go index 0740c27b9..e8af1d2d4 100644 --- a/runsc/boot/restore.go +++ b/runsc/boot/restore.go @@ -315,15 +315,19 @@ func (r *restorer) restore(l *Loader) error { r.pagesMetadata.Close() } - if err := postRestoreImpl(l); err != nil { - return err - } + go func() { + if err := postRestoreImpl(l); err != nil { + log.Warningf("Killing the sandbox after post restore work failed: %w", err) + l.k.Kill(linux.WaitStatusTerminationSignal(linux.SIGKILL)) + return + } - // Restore was successful, so increment the checkpoint count manually. The - // count was saved while the previous kernel was being saved and checkpoint - // success was unknown at that time. Now we know the checkpoint succeeded. - l.k.IncCheckpointCount() - log.Infof("Restore successful") + // Restore was successful, so increment the checkpoint count manually. The + // count was saved while the previous kernel was being saved and checkpoint + // success was unknown at that time. Now we know the checkpoint succeeded. + l.k.IncCheckpointCount() + log.Infof("Restore successful") + }() return nil }