@@ -39,6 +39,7 @@ import (
39
39
"github.com/containerd/nerdctl/v2/pkg/bypass4netnsutil"
40
40
"github.com/containerd/nerdctl/v2/pkg/dnsutil/hostsstore"
41
41
"github.com/containerd/nerdctl/v2/pkg/labels"
42
+ "github.com/containerd/nerdctl/v2/pkg/lockutil"
42
43
"github.com/containerd/nerdctl/v2/pkg/namestore"
43
44
"github.com/containerd/nerdctl/v2/pkg/netutil"
44
45
"github.com/containerd/nerdctl/v2/pkg/netutil/nettype"
@@ -92,6 +93,26 @@ func Run(stdin io.Reader, stderr io.Writer, event, dataStore, cniPath, cniNetcon
92
93
}
93
94
}()
94
95
96
+ // FIXME: CNI plugins are not safe to use concurrently
97
+ // See
98
+ // https://github.com/containerd/nerdctl/issues/3518
99
+ // https://github.com/containerd/nerdctl/issues/2908
100
+ // and likely others
101
+ // Fixing these issues would require a lot of work, possibly even stopping using individual cni binaries altogether
102
+ // or at least being very mindful in what operation we call inside CNIEnv at what point, with filesystem locking.
103
+ // This below is a stopgap solution that just enforces a global lock
104
+ // Note this here is probably not enough, as concurrent CNI operations may happen outside of the scope of ocihooks
105
+ // through explicit calls to Remove, etc.
106
+ err = os .MkdirAll (cniNetconfPath , 0o700 )
107
+ if err != nil {
108
+ return err
109
+ }
110
+ lock , err := lockutil .Lock (cniNetconfPath )
111
+ if err != nil {
112
+ return err
113
+ }
114
+ defer lockutil .Unlock (lock )
115
+
95
116
opts , err := newHandlerOpts (& state , dataStore , cniPath , cniNetconfPath )
96
117
if err != nil {
97
118
return err
0 commit comments