fix(resolver): prevent double-close panic in DNSResolver.Stop()
Use atomic Swap instead of Load+close+Store to eliminate the race window where concurrent Stop() calls could both pass the check.
This commit is contained in:
parent
ba0b3c55bb
commit
c2dd4fa9a3
@ -406,12 +406,11 @@ func (r *DNSResolver) doRefresh() {
|
|||||||
|
|
||||||
// Stop 停止解析器。
|
// Stop 停止解析器。
|
||||||
func (r *DNSResolver) Stop() error {
|
func (r *DNSResolver) Stop() error {
|
||||||
if !r.started.Load() {
|
if !r.started.Swap(false) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
close(r.stopCh)
|
close(r.stopCh)
|
||||||
r.started.Store(false)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user