Skip to content

Commit

Permalink
Control concurrency using sync.Mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwinger233 committed Jan 10, 2024
1 parent 380778f commit 24249e8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions control/netns_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
)

type DaeNetns struct {
once sync.Once
mu sync.Mutex

dae0, dae0peer netlink.Link
hostNs, daeNs netns.NsHandle
Expand All @@ -41,11 +41,15 @@ func (ns *DaeNetns) Setup() (err error) {
return nil
}

ns.once.Do(func() {
if err = ns.setup(); err != nil {
logrus.Fatal("Failed to setup dae netns: %v", err)
}
})
ns.mu.Lock()
defer ns.mu.Unlock()
if ns.daeNs != 0 && ns.hostNs != 0 {
return nil
}
if err = ns.setup(); err != nil {
ns.daeNs = 0
ns.hostNs = 0
}
return err
}

Expand Down

0 comments on commit 24249e8

Please sign in to comment.