@ -213,8 +213,8 @@ func (r *Resolver) LookupIP(ctx context.Context, host string) (ip, v6 netip.Addr
return ip , ip6 , allIPs , nil
return ip , ip6 , allIPs , nil
}
}
ch := r . sf . DoChan ( host, func ( ) ( ret ipRes , _ error ) {
ch := r . sf . DoChan Context ( ctx, host, func ( ctx context . Context ) ( ret ipRes , _ error ) {
ip , ip6 , allIPs , err := r . lookupIP ( host)
ip , ip6 , allIPs , err := r . lookupIP ( ctx, host)
if err != nil {
if err != nil {
return ret , err
return ret , err
}
}
@ -275,30 +275,30 @@ func (r *Resolver) lookupTimeoutForHost(host string) time.Duration {
return 10 * time . Second
return 10 * time . Second
}
}
func ( r * Resolver ) lookupIP ( host string ) ( ip , ip6 netip . Addr , allIPs [ ] netip . Addr , err error ) {
func ( r * Resolver ) lookupIP ( ctx context . Context , host string ) ( ip , ip6 netip . Addr , allIPs [ ] netip . Addr , err error ) {
if ip , ip6 , allIPs , ok := r . lookupIPCache ( host ) ; ok {
if ip , ip6 , allIPs , ok := r . lookupIPCache ( host ) ; ok {
r . dlogf ( "%q found in cache as %v" , host , ip )
r . dlogf ( "%q found in cache as %v" , host , ip )
return ip , ip6 , allIPs , nil
return ip , ip6 , allIPs , nil
}
}
ctx, c ancel := context . WithTimeout ( c on te xt. Background ( ) , r . lookupTimeoutForHost ( host ) )
lookupCtx, lookupC ancel := context . WithTimeout ( c tx, r . lookupTimeoutForHost ( host ) )
defer c ancel( )
defer lookupC ancel( )
ips , err := r . fwd ( ) . LookupNetIP ( c tx, "ip" , host )
ips , err := r . fwd ( ) . LookupNetIP ( lookupC tx, "ip" , host )
if err != nil || len ( ips ) == 0 {
if err != nil || len ( ips ) == 0 {
if resolver , ok := r . cloudHostResolver ( ) ; ok {
if resolver , ok := r . cloudHostResolver ( ) ; ok {
r . dlogf ( "resolving %q via cloud resolver" , host )
r . dlogf ( "resolving %q via cloud resolver" , host )
ips , err = resolver . LookupNetIP ( c tx, "ip" , host )
ips , err = resolver . LookupNetIP ( lookupC tx, "ip" , host )
}
}
}
}
if ( err != nil || len ( ips ) == 0 ) && r . LookupIPFallback != nil {
if ( err != nil || len ( ips ) == 0 ) && r . LookupIPFallback != nil {
ctx, c ancel := context . WithTimeout ( c on te xt. Background ( ) , 30 * time . Second )
lookupCtx, lookupC ancel := context . WithTimeout ( c tx, 30 * time . Second )
defer c ancel( )
defer lookupC ancel( )
if err != nil {
if err != nil {
r . dlogf ( "resolving %q using fallback resolver due to error" , host )
r . dlogf ( "resolving %q using fallback resolver due to error" , host )
} else {
} else {
r . dlogf ( "resolving %q using fallback resolver due to no returned IPs" , host )
r . dlogf ( "resolving %q using fallback resolver due to no returned IPs" , host )
}
}
ips , err = r . LookupIPFallback ( c tx, host )
ips , err = r . LookupIPFallback ( lookupC tx, host )
}
}
if err != nil {
if err != nil {
return netip . Addr { } , netip . Addr { } , nil , err
return netip . Addr { } , netip . Addr { } , nil , err