mirror of
https://github.com/Alexey71/opera-proxy.git
synced 2026-05-13 14:11:00 +00:00
fast resolver: cancel queries lost race
This commit is contained in:
+4
-4
@@ -35,8 +35,8 @@ func NewFastResolver(resolvers ...LookupNetIPer) *FastResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r FastResolver) LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error) {
|
func (r FastResolver) LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error) {
|
||||||
masterNotInterested := make(chan struct{})
|
ctx, cl := context.WithCancel(ctx)
|
||||||
defer close(masterNotInterested)
|
defer cl()
|
||||||
errors := make(chan error)
|
errors := make(chan error)
|
||||||
success := make(chan []netip.Addr)
|
success := make(chan []netip.Addr)
|
||||||
for _, res := range r.upstreams {
|
for _, res := range r.upstreams {
|
||||||
@@ -45,12 +45,12 @@ func (r FastResolver) LookupNetIP(ctx context.Context, network, host string) ([]
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
select {
|
select {
|
||||||
case success <- addrs:
|
case success <- addrs:
|
||||||
case <-masterNotInterested:
|
case <-ctx.Done():
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
select {
|
select {
|
||||||
case errors <- err:
|
case errors <- err:
|
||||||
case <-masterNotInterested:
|
case <-ctx.Done():
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(res)
|
}(res)
|
||||||
|
|||||||
Reference in New Issue
Block a user