Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ type controller struct {
unWatchCh chan *endpoint
svcDb map[string]svcMap
nmap map[string]*netWatch
defOsSbox osl.Sandbox
sboxOnce sync.Once
sync.Mutex
}

Expand Down Expand Up @@ -492,12 +494,6 @@ func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (S
config: containerConfig{},
controller: c,
}
// This sandbox may be using an existing osl sandbox, sharing it with another sandbox
var peerSb Sandbox
c.WalkSandboxes(SandboxKeyWalker(&peerSb, sb.Key()))
if peerSb != nil {
sb.osSbox = peerSb.(*sandbox).osSbox
}

heap.Init(&sb.endpoints)

Expand All @@ -507,14 +503,26 @@ func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (S
return nil, err
}

c.Lock()
if sb.config.useDefaultSandBox {
c.sboxOnce.Do(func() {
c.defOsSbox, err = osl.NewSandbox(sb.Key(), false)
})

if err != nil {
c.sboxOnce = sync.Once{}
return nil, fmt.Errorf("failed to create default sandbox: %v", err)
}

sb.osSbox = c.defOsSbox
}

if sb.osSbox == nil && !sb.config.useExternalKey {
if sb.osSbox, err = osl.NewSandbox(sb.Key(), !sb.config.useDefaultSandBox); err != nil {
c.Unlock()
return nil, fmt.Errorf("failed to create new osl sandbox: %v", err)
}
}

c.Lock()
c.sandboxes[sb.id] = sb
c.Unlock()
defer func() {
Expand Down
2 changes: 1 addition & 1 deletion sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (sb *sandbox) Delete() error {
// likely not required any more. Drop it.
etchosts.Drop(sb.config.hostsPath)

if sb.osSbox != nil {
if sb.osSbox != nil && !sb.config.useDefaultSandBox {
sb.osSbox.Destroy()
}

Expand Down