Fix: upstream dns ExchangeContext workaround (#468)
This commit is contained in:
parent
2c0cc374d3
commit
e68c0d088b
4 changed files with 5 additions and 2 deletions
|
@ -59,6 +59,7 @@ func (p *Picker) Wait() interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitWithoutCancel blocks until the first result return, if timeout will return nil.
|
// WaitWithoutCancel blocks until the first result return, if timeout will return nil.
|
||||||
|
// The return of this function will not wait for the cancel of context.
|
||||||
func (p *Picker) WaitWithoutCancel() interface{} {
|
func (p *Picker) WaitWithoutCancel() interface{} {
|
||||||
select {
|
select {
|
||||||
case <-p.firstDone:
|
case <-p.firstDone:
|
||||||
|
|
|
@ -16,6 +16,7 @@ func (c *client) Exchange(m *D.Msg) (msg *D.Msg, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) {
|
func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) {
|
||||||
|
// Please note that miekg/dns ExchangeContext doesn't respond to context cancel.
|
||||||
msg, _, err = c.Client.ExchangeContext(ctx, m, c.Address)
|
msg, _, err = c.Client.ExchangeContext(ctx, m, c.Address)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,7 @@ func (r *Resolver) batchExchange(clients []resolver, m *D.Msg) (msg *D.Msg, err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
elm := fast.Wait()
|
elm := fast.WaitWithoutCancel()
|
||||||
if elm == nil {
|
if elm == nil {
|
||||||
return nil, errors.New("All DNS requests failed")
|
return nil, errors.New("All DNS requests failed")
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,7 @@ func transform(servers []NameServer) []resolver {
|
||||||
NextProtos: []string{"dns"},
|
NextProtos: []string{"dns"},
|
||||||
},
|
},
|
||||||
UDPSize: 4096,
|
UDPSize: 4096,
|
||||||
|
Timeout: 5 * time.Second,
|
||||||
},
|
},
|
||||||
Address: s.Addr,
|
Address: s.Addr,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue