@@ -505,24 +505,37 @@ func onCreateRuntime(opts *handlerOpts) error {
505
505
log .L .WithError (err ).Error ("failed re-acquiring name - see https://github.com/containerd/nerdctl/issues/2992" )
506
506
}
507
507
508
+ var netError error
508
509
if opts .cni != nil {
509
- if err = applyNetworkSettings (opts ); err != nil {
510
- return err
511
- }
510
+ netError = applyNetworkSettings (opts )
512
511
}
513
512
514
- // Set StartedAt
515
513
lf := state .NewLifecycleState (opts .state .Annotations [labels .StateDir ])
516
- return lf .WithLock (func () error {
514
+
515
+ return errors .Join (netError , lf .WithLock (func () error {
517
516
// Errors are voluntarily ignored here, as they should not be fatal.
518
517
// The lifecycle struct is also already warning about the issue.
519
518
_ = lf .Load ()
520
519
lf .StartedAt = time .Now ()
520
+ lf .CreateError = netError != nil
521
521
return lf .Save ()
522
- })
522
+ }))
523
523
}
524
524
525
525
func onPostStop (opts * handlerOpts ) error {
526
+ // See https://github.com/containerd/nerdctl/issues/3357
527
+ // Check if we actually errored during runtimeCreate
528
+ // If that is the case, CreateError is set, and we are in postStop while the container will NOT be deleted (see ticket).
529
+ // In that case, do NOT treat this as a deletion, as the container is still there.
530
+ // Reset CreateError, and return.
531
+ lf := state .NewLifecycleState (opts .state .Annotations [labels .StateDir ])
532
+ if lf .WithLock (lf .Load ) == nil {
533
+ if lf .CreateError {
534
+ lf .CreateError = false
535
+ return lf .WithLock (lf .Save )
536
+ }
537
+ }
538
+
526
539
ctx := context .Background ()
527
540
ns := opts .state .Annotations [labels .Namespace ]
528
541
if opts .cni != nil {
0 commit comments