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:
xfy 2026-06-03 01:07:54 +08:00
parent ba0b3c55bb
commit c2dd4fa9a3

View File

@ -406,12 +406,11 @@ func (r *DNSResolver) doRefresh() {
// Stop 停止解析器。
func (r *DNSResolver) Stop() error {
if !r.started.Load() {
if !r.started.Swap(false) {
return nil
}
close(r.stopCh)
r.started.Store(false)
return nil
}