Skip to content
Draft
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
13 changes: 8 additions & 5 deletions internal/shim/task/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,21 @@ func (s *service) shutdown(ctx context.Context) error {
// to flush ext4 journals and dirty pages to the virtio-blk devices.
// Best-effort with a short retry for transient EBUSY.
if vmc, err := s.sb.Client(); err != nil {
log.G(ctx).WithError(err).Warn("failed to get VM client; skipping unmount of block volumes before VM shutdown")
log.G(ctx).WithError(err).Warn("failed to get VM client; skipping unmount and guest shutdown before VM stop")
} else {
unmountCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
err := unmountAllWithRetry(unmountCtx, mountAPI.NewTTRPCMountClient(vmc))
cancel()
if err != nil {
log.G(ctx).WithError(err).Warn("failed to unmount all block volumes before VM shutdown")
}

shutdownCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
_, err = taskAPI.NewTTRPCTaskClient(vmc).Shutdown(shutdownCtx, &taskAPI.ShutdownRequest{})
cancel()
if err != nil {
log.G(ctx).WithError(err).Warn("failed to wait for guest shutdown before VM stop")
}
Comment on lines +164 to +169
}

if err := s.sb.Stop(ctx); err != nil {
Expand Down Expand Up @@ -709,10 +716,6 @@ func (s *service) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (*task
func (s *service) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (*ptypes.Empty, error) {
log.G(ctx).WithFields(log.Fields{"id": r.ID}).Info("shutdown")

// TODO: Should we forward this to VM?
// tc := taskAPI.NewTTRPCTaskClient(s.vm.Client())
// return tc.Shutdown(ctx, r)

s.initiateShutdownOnce.Do(s.initiateShutdown)

select {
Expand Down
13 changes: 8 additions & 5 deletions internal/vminit/task/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,18 +649,21 @@ func (s *service) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (*task

func (s *service) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (*ptypes.Empty, error) {
s.mu.Lock()
defer s.mu.Unlock()

// return out if the shim is still servicing containers
if len(s.containers) > 0 {
s.mu.Unlock()
return empty, nil
}
s.mu.Unlock()

// please make sure that temporary resource has been cleanup or registered
// for cleanup before calling shutdown
s.shutdown.Shutdown()

return empty, nil
select {
case <-s.shutdown.Done():
return empty, nil
case <-ctx.Done():
return nil, errgrpc.ToGRPC(ctx.Err())
}
}

func (s *service) Stats(ctx context.Context, r *taskAPI.StatsRequest) (*taskAPI.StatsResponse, error) {
Expand Down
1 change: 0 additions & 1 deletion pkg/vminit/initd/initd.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ func newService(ctx context.Context, config Config, shutdownSvc shutdown.Service
if err != nil {
return nil, err
}
shutdownSvc.RegisterCallback(ts.Shutdown)

registry.Register(&plugin.Registration{
Type: cplugins.InternalPlugin,
Expand Down
Loading