Skip to content

Commit

Permalink
ipn/proxies: stop existing proxy only if remove ok
Browse files Browse the repository at this point in the history
ignoramous committed Nov 22, 2024
1 parent 3316da3 commit ee5b040
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions intra/ipn/proxies.go
Original file line number Diff line number Diff line change
@@ -221,27 +221,29 @@ func NewProxifier(pctx context.Context, c protect.Controller, o x.ProxyListener)
}

func (px *proxifier) add(p Proxy) (ok bool) {
var old Proxy
id := p.ID()

px.Lock()
defer px.Unlock()

defer func() {
if ok {
core.Go("pxr.add: "+id, func() { px.obs.OnProxyAdded(id) })
}
}()

if pp := px.p[id]; pp != nil {
// new proxy, invoke Stop on old proxy
if pp != p {
core.Go("pxr.add: "+id, func() { // holding px.lock, so exec stop in a goroutine
_ = pp.Stop()
// onRmv is not sent here, as new proxy will be added
core.Go("pxr.add: "+id, func() {
px.obs.OnProxyAdded(id)
})
// new proxy, invoke Stop on old proxy
if old != nil && old.Handle() != p.Handle() {
// holding px.lock, so exec stop in a goroutine
core.Go("pxr.add.stop: "+id, func() {
_ = old.Stop()
// onRmv is not sent here, as one has just been added
})
}
}
}
}()

old = px.p[id]
if immutable(id) {
switch id {
case Exit:
@@ -280,7 +282,7 @@ func (px *proxifier) add(p Proxy) (ok bool) {
ok = true
}

log.D("proxy: add: proxy %s ok? %t", id, ok)
logeif(ok)("proxy: add: proxy %s ok? %t", id, ok)
return ok
}

0 comments on commit ee5b040

Please sign in to comment.