0.38.6_agent_hotfix
This commit is contained in:
1 parent
1239ff524d
commit
d4a604970e
14 files changed
+478
-162
No files matched your search
+37
-10
@@ -268,23 +268,50 @@ type ipDetector struct {
|
||||
mu sync.Mutex
|
||||
publicIP string
|
||||
expires time.Time
|
||||
fetching chan struct{}
|
||||
}
|
||||
|
||||
func (d *ipDetector) public(ctx context.Context, rawURL string) string {
|
||||
if rawURL == "" {
|
||||
return ""
|
||||
}
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
if time.Now().Before(d.expires) {
|
||||
return d.publicIP
|
||||
for {
|
||||
d.mu.Lock()
|
||||
if time.Now().Before(d.expires) {
|
||||
ip := d.publicIP
|
||||
d.mu.Unlock()
|
||||
return ip
|
||||
}
|
||||
if d.fetching != nil {
|
||||
done := d.fetching
|
||||
d.mu.Unlock()
|
||||
select {
|
||||
case <-done:
|
||||
continue
|
||||
case <-ctx.Done():
|
||||
return ""
|
||||
}
|
||||
}
|
||||
done := make(chan struct{})
|
||||
d.fetching = done
|
||||
d.mu.Unlock()
|
||||
|
||||
// Do not hold the cache mutex across the external HTTP lookup.
|
||||
ip := publicIPFromURL(ctx, rawURL)
|
||||
d.mu.Lock()
|
||||
if ctx.Err() == nil {
|
||||
d.publicIP = ip
|
||||
ttl := 5 * time.Minute
|
||||
if ip == "" {
|
||||
ttl = 30 * time.Second
|
||||
}
|
||||
d.expires = time.Now().Add(ttl)
|
||||
}
|
||||
d.fetching = nil
|
||||
close(done)
|
||||
d.mu.Unlock()
|
||||
return ip
|
||||
}
|
||||
d.publicIP = publicIPFromURL(ctx, rawURL)
|
||||
d.expires = time.Now().Add(5 * time.Minute)
|
||||
if d.publicIP == "" {
|
||||
d.expires = time.Now().Add(30 * time.Second)
|
||||
}
|
||||
return d.publicIP
|
||||
}
|
||||
|
||||
func mergeHostAddress(out *[]hostAddress, index map[string]int, candidate hostAddress) {
|
||||
|
||||
Reference in new issue
Block a user