mirror of
https://github.com/minio/minio.git
synced 2024-12-25 06:35:56 -05:00
fix: change defaults for DNS cache dialer (#11145)
This commit is contained in:
parent
6df6ac0f34
commit
3e792ae2a2
@ -51,7 +51,7 @@ func init() {
|
||||
logger.RegisterError(config.FmtError)
|
||||
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
globalDNSCache = xhttp.NewDNSCache(3*time.Second, 10*time.Second)
|
||||
globalDNSCache = xhttp.NewDNSCache(10*time.Second, 3*time.Second)
|
||||
|
||||
initGlobalContext()
|
||||
|
||||
|
@ -98,7 +98,8 @@ type DNSCache struct {
|
||||
lookupTimeout time.Duration
|
||||
|
||||
cache map[string][]string
|
||||
closer func()
|
||||
doneOnce sync.Once
|
||||
doneCh chan struct{}
|
||||
}
|
||||
|
||||
// NewDNSCache initializes DNS cache resolver and starts auto refreshing
|
||||
@ -113,26 +114,24 @@ func NewDNSCache(freq time.Duration, lookupTimeout time.Duration) *DNSCache {
|
||||
lookupTimeout = defaultLookupTimeout
|
||||
}
|
||||
|
||||
ticker := time.NewTicker(freq)
|
||||
ch := make(chan struct{})
|
||||
closer := func() {
|
||||
ticker.Stop()
|
||||
close(ch)
|
||||
}
|
||||
|
||||
r := &DNSCache{
|
||||
lookupHostFn: net.DefaultResolver.LookupHost,
|
||||
lookupTimeout: lookupTimeout,
|
||||
cache: make(map[string][]string, cacheSize),
|
||||
closer: closer,
|
||||
doneCh: make(chan struct{}),
|
||||
}
|
||||
|
||||
timer := time.NewTimer(freq)
|
||||
go func() {
|
||||
defer timer.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
case <-timer.C:
|
||||
timer.Reset(freq)
|
||||
|
||||
r.Refresh()
|
||||
case <-ch:
|
||||
case <-r.doneCh:
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -188,10 +187,7 @@ func (r *DNSCache) Refresh() {
|
||||
|
||||
// Stop stops auto refreshing.
|
||||
func (r *DNSCache) Stop() {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
if r.closer != nil {
|
||||
r.closer()
|
||||
r.closer = nil
|
||||
}
|
||||
r.doneOnce.Do(func() {
|
||||
close(r.doneCh)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user