Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 7e98d86

Browse files
authored
Merge pull request #3020 from jcvenegas/stable-1.10-backports
Stable 1.10 backports
2 parents cfe182d + 6f33f4e commit 7e98d86

2 files changed

Lines changed: 47 additions & 26 deletions

File tree

containerd-shim-v2/service.go

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -342,34 +342,46 @@ func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *
342342
s.mu.Lock()
343343
defer s.mu.Unlock()
344344

345-
var c *container
346-
347-
c, err = create(ctx, s, r)
348-
if err != nil {
349-
return nil, err
350-
}
351-
352-
c.status = task.StatusCreated
353-
354-
s.containers[r.ID] = c
345+
type Result struct {
346+
container *container
347+
err error
348+
}
349+
ch := make(chan Result, 1)
350+
go func() {
351+
container, err := create(ctx, s, r)
352+
ch <- Result{container, err}
353+
}()
355354

356-
s.send(&eventstypes.TaskCreate{
357-
ContainerID: r.ID,
358-
Bundle: r.Bundle,
359-
Rootfs: r.Rootfs,
360-
IO: &eventstypes.TaskIO{
361-
Stdin: r.Stdin,
362-
Stdout: r.Stdout,
363-
Stderr: r.Stderr,
364-
Terminal: r.Terminal,
365-
},
366-
Checkpoint: r.Checkpoint,
367-
Pid: s.pid,
368-
})
355+
select {
356+
case <-ctx.Done():
357+
return nil, errors.Errorf("create container timeout: %v", r.ID)
358+
case res := <-ch:
359+
if res.err != nil {
360+
return nil, res.err
361+
}
362+
container := res.container
363+
container.status = task.StatusCreated
364+
365+
s.containers[r.ID] = container
366+
367+
s.send(&eventstypes.TaskCreate{
368+
ContainerID: r.ID,
369+
Bundle: r.Bundle,
370+
Rootfs: r.Rootfs,
371+
IO: &eventstypes.TaskIO{
372+
Stdin: r.Stdin,
373+
Stdout: r.Stdout,
374+
Stderr: r.Stderr,
375+
Terminal: r.Terminal,
376+
},
377+
Checkpoint: r.Checkpoint,
378+
Pid: s.pid,
379+
})
369380

370-
return &taskAPI.CreateTaskResponse{
371-
Pid: s.pid,
372-
}, nil
381+
return &taskAPI.CreateTaskResponse{
382+
Pid: s.pid,
383+
}, nil
384+
}
373385
}
374386

375387
// Start a process

virtcontainers/sandbox.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,10 @@ func (s *Sandbox) CreateContainer(contConfig ContainerConfig) (VCContainer, erro
11631163
if len(s.config.Containers) > 0 {
11641164
// delete container config
11651165
s.config.Containers = s.config.Containers[:len(s.config.Containers)-1]
1166+
// need to flush change to persist storage
1167+
if newErr := s.storeSandbox(); newErr != nil {
1168+
s.Logger().WithError(newErr).Error("Fail to flush s.config.Containers change into sandbox store")
1169+
}
11661170
}
11671171
if !storeAlreadyExists {
11681172
if delerr := c.store.Delete(); delerr != nil {
@@ -1594,6 +1598,11 @@ func (s *Sandbox) Stop(force bool) error {
15941598
return err
15951599
}
15961600

1601+
// Stop communicating with the agent.
1602+
if err := s.agent.disconnect(); err != nil && !force {
1603+
return err
1604+
}
1605+
15971606
return nil
15981607
}
15991608

0 commit comments

Comments
 (0)