@@ -222,7 +222,7 @@ func (r *Resolver) LookupIP(ctx context.Context, host string) (ip, v6 netip.Addr
222
222
}
223
223
224
224
ch := r .sf .DoChan (host , func () (ret ipRes , _ error ) {
225
- ip , ip6 , allIPs , err := r .lookupIP (host )
225
+ ip , ip6 , allIPs , err := r .lookupIP (ctx , host )
226
226
if err != nil {
227
227
return ret , err
228
228
}
@@ -283,30 +283,30 @@ func (r *Resolver) lookupTimeoutForHost(host string) time.Duration {
283
283
return 10 * time .Second
284
284
}
285
285
286
- func (r * Resolver ) lookupIP (host string ) (ip , ip6 netip.Addr , allIPs []netip.Addr , err error ) {
286
+ func (r * Resolver ) lookupIP (ctx context. Context , host string ) (ip , ip6 netip.Addr , allIPs []netip.Addr , err error ) {
287
287
if ip , ip6 , allIPs , ok := r .lookupIPCache (host ); ok {
288
288
r .dlogf ("%q found in cache as %v" , host , ip )
289
289
return ip , ip6 , allIPs , nil
290
290
}
291
291
292
- ctx , cancel := context .WithTimeout (context . Background () , r .lookupTimeoutForHost (host ))
293
- defer cancel ()
294
- ips , err := r .fwd ().LookupNetIP (ctx , "ip" , host )
292
+ lookupCtx , lookupCancel := context .WithTimeout (ctx , r .lookupTimeoutForHost (host ))
293
+ defer lookupCancel ()
294
+ ips , err := r .fwd ().LookupNetIP (lookupCtx , "ip" , host )
295
295
if err != nil || len (ips ) == 0 {
296
296
if resolver , ok := r .cloudHostResolver (); ok {
297
297
r .dlogf ("resolving %q via cloud resolver" , host )
298
- ips , err = resolver .LookupNetIP (ctx , "ip" , host )
298
+ ips , err = resolver .LookupNetIP (lookupCtx , "ip" , host )
299
299
}
300
300
}
301
301
if (err != nil || len (ips ) == 0 ) && r .LookupIPFallback != nil {
302
- ctx , cancel := context .WithTimeout (context . Background () , 30 * time .Second )
303
- defer cancel ()
302
+ lookupCtx , lookupCancel := context .WithTimeout (ctx , 30 * time .Second )
303
+ defer lookupCancel ()
304
304
if err != nil {
305
305
r .dlogf ("resolving %q using fallback resolver due to error" , host )
306
306
} else {
307
307
r .dlogf ("resolving %q using fallback resolver due to no returned IPs" , host )
308
308
}
309
- ips , err = r .LookupIPFallback (ctx , host )
309
+ ips , err = r .LookupIPFallback (lookupCtx , host )
310
310
}
311
311
if err != nil {
312
312
return netip.Addr {}, netip.Addr {}, nil , err
0 commit comments