Skip to content

Commit

Permalink
fix locks
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeZappa87 committed Nov 26, 2024
1 parent d96cc3b commit 5e08bf0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func (c *libcni) Setup(ctx context.Context, id string, path string, opts ...Name
if err := c.ready(); err != nil {
return nil, err
}
c.RLock()
defer c.RUnlock()
ns, err := newNamespace(id, path, opts...)
if err != nil {
return nil, err
Expand All @@ -182,6 +184,8 @@ func (c *libcni) SetupSerially(ctx context.Context, id string, path string, opts
if err := c.ready(); err != nil {
return nil, err
}
c.RLock()
defer c.RUnlock()
ns, err := newNamespace(id, path, opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -245,6 +249,8 @@ func (c *libcni) Remove(ctx context.Context, id string, path string, opts ...Nam
if err := c.ready(); err != nil {
return err
}
c.RLock()
defer c.RUnlock()
ns, err := newNamespace(id, path, opts...)
if err != nil {
return err
Expand Down Expand Up @@ -273,6 +279,8 @@ func (c *libcni) Check(ctx context.Context, id string, path string, opts ...Name
if err := c.ready(); err != nil {
return err
}
c.RLock()
defer c.RUnlock()
ns, err := newNamespace(id, path, opts...)
if err != nil {
return err
Expand Down Expand Up @@ -322,8 +330,6 @@ func (c *libcni) reset() {
}

func (c *libcni) ready() error {
c.RLock()
defer c.RUnlock()
if len(c.networks) < c.networkCount {
return ErrCNINotInitialized
}
Expand Down

0 comments on commit 5e08bf0

Please sign in to comment.