mirror of
https://github.com/coredns/coredns.git
synced 2025-12-12 13:25:11 -05:00
Prevent fail counter of a proxy overflows (#5990)
Signed-off-by: vanceli <vanceli@tencent.com> Signed-off-by: Vance Li <vncl@YingyingM1.local> Co-authored-by: vanceli <vanceli@tencent.com>
This commit is contained in:
@@ -93,6 +93,16 @@ func (p *Proxy) SetReadTimeout(duration time.Duration) {
|
||||
p.readTimeout = duration
|
||||
}
|
||||
|
||||
// incrementFails increments the number of fails safely.
|
||||
func (p *Proxy) incrementFails() {
|
||||
curVal := atomic.LoadUint32(&p.fails)
|
||||
if curVal > curVal+1 {
|
||||
// overflow occurred, do not update the counter again
|
||||
return
|
||||
}
|
||||
atomic.AddUint32(&p.fails, 1)
|
||||
}
|
||||
|
||||
const (
|
||||
maxTimeout = 2 * time.Second
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user