Skip to content

Commit a00108f

Browse files
committed
dnsx/transport: on stopAll, stop & clear all transports
1 parent 365539c commit a00108f

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

intra/dnsx/transport.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ func NewResolver(pctx context.Context, fakeaddrs string, dtr x.DNSTransport, l x
212212
} else {
213213
ctr := NewCachingTransport(tr, ttl10m)
214214
r.Lock()
215-
r.transports[tr.ID().V()] = tr // regular
215+
r.transports[idstr(tr)] = tr // regular
216216
if ctr != nil {
217-
r.transports[ctr.ID().V()] = ctr // cached
217+
r.transports[idstr(ctr)] = ctr // cached
218218
} else {
219219
log.W("dns: no caching transport for %s", tr.ID())
220220
}
@@ -918,7 +918,7 @@ func (r *resolver) accept(c io.ReadWriteCloser, uid string) {
918918
// StopAll stops all transports and closes the resolver.
919919
func (r *resolver) StopAll() {
920920
r.once.Do(func() {
921-
core.Go("r.onStop", func() { r.listener.OnDNSStopped() })
921+
defer core.Go("r.onStop", func() { r.listener.OnDNSStopped() })
922922
r.done()
923923

924924
if dc, err := r.dcProxy(); err == nil {
@@ -929,17 +929,29 @@ func (r *resolver) StopAll() {
929929
_ = p.Stop()
930930
}
931931

932+
// Stop all transports in a separate goroutine to avoid blocking
933+
core.Go("r.stopAllTransports", func() {
934+
r.Lock()
935+
for _, tr := range r.transports {
936+
_ = tr.Stop()
937+
// r.gateway.onStopped(id) is not required
938+
// as the entire setup is closed and going away
939+
}
940+
clear(r.transports)
941+
r.Unlock()
942+
})
943+
932944
close(r.smms) // close listener chan
933945
})
934946
}
935947

936948
func (r *resolver) all() []Transport {
937949
r.RLock()
950+
defer r.RUnlock()
938951
out := make([]Transport, 0, len(r.transports))
939952
for _, t := range r.transports {
940953
out = append(out, t)
941954
}
942-
r.RUnlock()
943955
return out
944956
}
945957

0 commit comments

Comments
 (0)