fix: ResolveNetip should use child context to prevent resend after func exit

This commit is contained in:
mzz2017 2023-02-09 13:45:49 +08:00
parent 55bd309b6b
commit 7f5e4f8349

View File

@ -37,6 +37,8 @@ func SystemDns() (dns netip.AddrPort, err error) {
}
func ResolveNetip(ctx context.Context, d proxy.Dialer, dns netip.AddrPort, host string, typ dnsmessage.Type) (addrs []netip.Addr, err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
if addr, err := netip.ParseAddr(host); err == nil {
if (addr.Is4() || addr.Is4In6()) && typ == dnsmessage.TypeA {
return []netip.Addr{addr}, nil