@@ -22,6 +22,8 @@ import (
22
22
"path/filepath"
23
23
"strings"
24
24
25
+ "github.com/containerd/log"
26
+
25
27
"github.com/containerd/nerdctl/v2/pkg/identifiers"
26
28
"github.com/containerd/nerdctl/v2/pkg/lockutil"
27
29
)
@@ -56,12 +58,21 @@ func (x *nameStore) Acquire(name, id string) error {
56
58
}
57
59
fn := func () error {
58
60
fileName := filepath .Join (x .dir , name )
59
- // If containerd was bounced, previously running containers that would get restarted will go again through
60
- // onCreateRuntime (unlike in a "normal" stop/start flow).
61
- // As such, we need to allow reacquiring by the same id
62
- // See: https://github.com/containerd/nerdctl/issues/3354
63
- if b , err := os .ReadFile (fileName ); err == nil && string (b ) != id {
64
- return fmt .Errorf ("name %q is already used by ID %q" , name , string (b ))
61
+ if b , err := os .ReadFile (fileName ); err == nil {
62
+ if strings .TrimSpace (string (b )) == "" {
63
+ // currently acquired for an empty id - this obviously should never happen
64
+ // this is recoverable, and we are not hard erroring, but still indicative that something was wrong
65
+ // https://github.com/containerd/nerdctl/issues/3351
66
+ log .L .Errorf ("current name %q is reserved for a an empty id - please report this is as a bug" , name )
67
+ } else if string (b ) != id {
68
+ // if acquired by a different container, we error out here
69
+ return fmt .Errorf ("name %q is already used by ID %q" , name , string (b ))
70
+ }
71
+ // Otherwise, this is just re-acquiring after a restart
72
+ // For example, if containerd was bounced, previously running containers that would get restarted will go
73
+ // again through onCreateRuntime (unlike in a "normal" stop/start flow).
74
+ // As such, we are allowing reacquiring by the same id
75
+ // See: https://github.com/containerd/nerdctl/issues/3354
65
76
}
66
77
return os .WriteFile (fileName , []byte (id ), 0600 )
67
78
}
0 commit comments