mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-14 21:31:16 +08:00
fix: reset timeout in exchangeWithoutCache's singleflight
This commit is contained in:
parent
2dc62024fe
commit
8b848b62bb
@ -187,7 +187,10 @@ func (r *Resolver) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, e
|
||||
func (r *Resolver) exchangeWithoutCache(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) {
|
||||
q := m.Question[0]
|
||||
|
||||
ret, err, shared := r.group.Do(q.String(), func() (result any, err error) {
|
||||
ch := r.group.DoChan(q.String(), func() (result any, err error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), resolver.DefaultDNSTimeout) // reset timeout in singleflight
|
||||
defer cancel()
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
return
|
||||
@ -209,6 +212,21 @@ func (r *Resolver) exchangeWithoutCache(ctx context.Context, m *D.Msg) (msg *D.M
|
||||
return r.batchExchange(ctx, r.main, m)
|
||||
})
|
||||
|
||||
var result singleflight.Result
|
||||
|
||||
select {
|
||||
case result = <-ch:
|
||||
break
|
||||
case <-ctx.Done():
|
||||
select {
|
||||
case result = <-ch:
|
||||
break
|
||||
}
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
|
||||
ret, err, shared := result.Val, result.Err, result.Shared
|
||||
|
||||
if err == nil {
|
||||
msg = ret.(*D.Msg)
|
||||
if shared {
|
||||
|
Loading…
Reference in New Issue
Block a user