mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2024-12-30 02:37:01 +00:00
fix a potential context leak
This commit is contained in:
@@ -33,13 +33,15 @@ func dnsExchange(r *D.Msg) (msg *D.Msg) {
|
||||
c := new(D.Client)
|
||||
c.Net = "tcp"
|
||||
for _, dns := range backendDNS {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
msg, _, _ = c.ExchangeContext(ctx, r, dns)
|
||||
cancel() // call cancel as soon as the operations running in this Context complete
|
||||
if msg != nil {
|
||||
// success, exit query.
|
||||
break
|
||||
// success, exit query
|
||||
goto Out
|
||||
}
|
||||
}
|
||||
Out:
|
||||
return msg
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user