Skip to content
Open
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
30 changes: 28 additions & 2 deletions adapter/outboundgroup/fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,36 @@ func (f *Fallback) Unwrap(metadata *C.Metadata, touch bool) C.Proxy {

func (f *Fallback) findAliveProxy(touch bool) C.Proxy {
proxies := f.GetProxies(touch)

// Tracked during the same pass so the members are walked once: if nothing
// is alive, a member whose alive flag is merely stale (e.g. it was checked
// before its provider finished loading) is still a better bet than one
// currently resolving to REJECT, which would silently blackhole traffic.
var firstNotBlackholed C.Proxy

for _, proxy := range proxies {
// AliveForTestUrl first: it is a plain flag read, while resolvesToReject
// may walk a whole sub-group. Short-circuiting on it keeps the common
// case cheap and avoids unwrapping members that are dead anyway.
usable := false
if proxy.AliveForTestUrl(f.testUrl) {
if !resolvesToReject(proxy) {
usable = true
if firstNotBlackholed == nil {
firstNotBlackholed = proxy
}
}
} else if firstNotBlackholed == nil && !resolvesToReject(proxy) {
firstNotBlackholed = proxy
}

if len(f.selected) == 0 {
if proxy.AliveForTestUrl(f.testUrl) {
if usable {
return proxy
}
} else {
if proxy.Name() == f.selected {
if proxy.AliveForTestUrl(f.testUrl) {
if usable {
return proxy
} else {
f.selected = ""
Expand All @@ -120,6 +142,10 @@ func (f *Fallback) findAliveProxy(touch bool) C.Proxy {
}
}

if firstNotBlackholed != nil {
return firstNotBlackholed
}

return proxies[0]
}

Expand Down
Loading