Skip to content

Commit bacbce6

Browse files
committed
proxy sandbox removal with strictly exact ip
1 parent b33668c commit bacbce6

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

packages/orchestrator/internal/proxy/proxy.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"net/url"
1616
"strconv"
1717
"strings"
18+
"sync"
1819
"time"
1920
)
2021

@@ -28,6 +29,7 @@ var browserIdentityKeywords = []string{
2829
type SandboxProxy struct {
2930
sandboxes *smap.Map[string]
3031
server *http.Server
32+
mu sync.Mutex
3133
}
3234

3335
func New(port uint) *SandboxProxy {
@@ -40,11 +42,17 @@ func New(port uint) *SandboxProxy {
4042
}
4143

4244
func (p *SandboxProxy) AddSandbox(sandboxID, ip string) {
45+
p.mu.Lock()
46+
defer p.mu.Unlock()
47+
4348
p.sandboxes.Insert(sandboxID, ip)
4449
}
4550

46-
func (p *SandboxProxy) RemoveSandbox(sandboxID string) {
47-
p.sandboxes.Remove(sandboxID)
51+
func (p *SandboxProxy) RemoveSandbox(sandboxID string, ip string) {
52+
p.mu.Lock()
53+
defer p.mu.Unlock()
54+
55+
p.sandboxes.RemoveCb(sandboxID, func(k string, v string, ok bool) bool { return v == ip })
4856
}
4957

5058
func (p *SandboxProxy) Start() error {

packages/orchestrator/internal/sandbox/sandbox_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func NewSandbox(
322322

323323
cleanup.Add(func() error {
324324
dns.Remove(config.SandboxId, ips.HostIP())
325-
proxy.RemoveSandbox(config.SandboxId)
325+
proxy.RemoveSandbox(config.SandboxId, ips.HostIP())
326326

327327
return nil
328328
})

packages/orchestrator/internal/server/sandboxes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (s *server) Delete(ctxConn context.Context, in *orchestrator.SandboxDeleteR
183183

184184
// Don't allow connecting to the sandbox anymore.
185185
s.dns.Remove(in.SandboxId, sbx.Slot.HostIP())
186-
s.proxy.RemoveSandbox(in.SandboxId)
186+
s.proxy.RemoveSandbox(in.SandboxId, sbx.Slot.HostIP())
187187

188188
// Remove the sandbox from the cache to prevent loading it again in API during the time the instance is stopping.
189189
// Old comment:

0 commit comments

Comments
 (0)