fix: rollback batchExchange's code
This commit is contained in:
parent
b8b3c9ef9f
commit
4ea4221380
1 changed files with 1 additions and 22 deletions
23
dns/util.go
23
dns/util.go
|
@ -216,7 +216,7 @@ func batchExchange(ctx context.Context, clients []dnsClient, m *D.Msg) (msg *D.M
|
|||
fast, ctx := picker.WithTimeout[*D.Msg](ctx, resolver.DefaultDNSTimeout)
|
||||
for _, client := range clients {
|
||||
r := client
|
||||
fn := func() (*D.Msg, error) {
|
||||
fast.Go(func() (*D.Msg, error) {
|
||||
m, err := r.ExchangeContext(ctx, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -224,27 +224,6 @@ func batchExchange(ctx context.Context, clients []dnsClient, m *D.Msg) (msg *D.M
|
|||
return nil, errors.New("server failure")
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
fast.Go(func() (*D.Msg, error) {
|
||||
ch := make(chan result, 1)
|
||||
go func() {
|
||||
m, err := fn()
|
||||
ch <- result{
|
||||
Msg: m,
|
||||
Error: err,
|
||||
}
|
||||
}()
|
||||
select {
|
||||
case r := <-ch:
|
||||
return r.Msg, r.Error
|
||||
case <-ctx.Done():
|
||||
select {
|
||||
case r := <-ch:
|
||||
return r.Msg, r.Error
|
||||
default:
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue