Skip to content

Commit e68c0d0

Browse files
comzyhDreamacro
authored andcommitted
Fix: upstream dns ExchangeContext workaround (#468)
1 parent 2c0cc37 commit e68c0d0

File tree

4 files changed

+5
-2
lines changed

4 files changed

+5
-2
lines changed

common/picker/picker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (p *Picker) Wait() interface{} {
5959
}
6060

6161
// WaitWithoutCancel blocks until the first result return, if timeout will return nil.
62+
// The return of this function will not wait for the cancel of context.
6263
func (p *Picker) WaitWithoutCancel() interface{} {
6364
select {
6465
case <-p.firstDone:

dns/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func (c *client) Exchange(m *D.Msg) (msg *D.Msg, err error) {
1616
}
1717

1818
func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) {
19+
// Please note that miekg/dns ExchangeContext doesn't respond to context cancel.
1920
msg, _, err = c.Client.ExchangeContext(ctx, m, c.Address)
2021
return
2122
}

dns/resolver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (r *Resolver) IsFakeIP(ip net.IP) bool {
180180
}
181181

182182
func (r *Resolver) batchExchange(clients []resolver, m *D.Msg) (msg *D.Msg, err error) {
183-
fast, ctx := picker.WithTimeout(context.Background(), time.Second * 5)
183+
fast, ctx := picker.WithTimeout(context.Background(), time.Second*5)
184184
for _, client := range clients {
185185
r := client
186186
fast.Go(func() (interface{}, error) {
@@ -192,7 +192,7 @@ func (r *Resolver) batchExchange(clients []resolver, m *D.Msg) (msg *D.Msg, err
192192
})
193193
}
194194

195-
elm := fast.Wait()
195+
elm := fast.WaitWithoutCancel()
196196
if elm == nil {
197197
return nil, errors.New("All DNS requests failed")
198198
}

dns/util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ func transform(servers []NameServer) []resolver {
134134
NextProtos: []string{"dns"},
135135
},
136136
UDPSize: 4096,
137+
Timeout: 5 * time.Second,
137138
},
138139
Address: s.Addr,
139140
})

0 commit comments

Comments
 (0)