Skip to content

Commit 537afb1

Browse files
authored
Merge pull request containerd#3921 from darfux/v2_try_to_delete_shim_when_create_fail
v2: Call shim.Delete at first when create is failed
2 parents 06b15f0 + d82fa43 commit 537afb1

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

runtime/v2/binary.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (b *binary) Start(ctx context.Context, opts *types.Any, onClose func()) (_
7474
if err != nil {
7575
return nil, err
7676
}
77-
f, err := openShimLog(ctx, b.bundle, client.AnonDialer)
77+
f, err := openShimLog(context.Background(), b.bundle, client.AnonDialer)
7878
if err != nil {
7979
return nil, errors.Wrap(err, "open shim log pipe")
8080
}

runtime/v2/manager.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/containerd/containerd/metadata"
3030
"github.com/containerd/containerd/mount"
3131
"github.com/containerd/containerd/namespaces"
32+
"github.com/containerd/containerd/pkg/timeout"
3233
"github.com/containerd/containerd/platforms"
3334
"github.com/containerd/containerd/plugin"
3435
"github.com/containerd/containerd/runtime"
@@ -154,8 +155,13 @@ func (m *TaskManager) Create(ctx context.Context, id string, opts runtime.Create
154155
}
155156
defer func() {
156157
if err != nil {
157-
shim.Shutdown(ctx)
158-
shim.Close()
158+
dctx, cancel := timeout.WithContext(context.Background(), cleanupTimeout)
159+
defer cancel()
160+
_, errShim := shim.Delete(dctx)
161+
if errShim != nil {
162+
shim.Shutdown(ctx)
163+
shim.Close()
164+
}
159165
}
160166
}()
161167
t, err := shim.Create(ctx, opts)

runtime/v2/shim.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ func (s *shim) Delete(ctx context.Context) (*runtime.Exit, error) {
235235
// this seems dirty but it cleans up the API across runtimes, tasks, and the service
236236
s.rtTasks.Delete(ctx, s.ID())
237237
if err := s.waitShutdown(ctx); err != nil {
238-
log.G(ctx).WithError(err).Error("failed to shutdown shim")
238+
log.G(ctx).WithField("id", s.ID()).WithError(err).Error("failed to shutdown shim")
239239
}
240240
s.Close()
241241
if err := s.bundle.Delete(); err != nil {
242-
log.G(ctx).WithError(err).Error("failed to delete bundle")
242+
log.G(ctx).WithField("id", s.ID()).WithError(err).Error("failed to delete bundle")
243243
}
244244
if shimErr != nil {
245245
return nil, shimErr

0 commit comments

Comments
 (0)