inet_res.lookup resets the resolved nameservers in inet_db #9224
Description
Note, I'm using Elixir, so I might mess up some of the syntax. My apologies in advance!
Describe the bug
On localhost, dns lookups were slow (700ms). This was after setting the ns to 1.1.1.1. When I looked up a DNS entry with inet_res.lookup, and then looked at the resolved ns, they were different than before I ran. I'm not sure where these name servers are coming from, but they're very slow (I'm assuming from my internet provider). Regardless, when I set the NS for inet, they should not be erased when using inet_res.lookup
To Reproduce
- Log the ets table
`:ets.tab2list(:inet_db)`
[
socks5_noproxy: [],
res_recurse: true,
res_id: 0,
res_resolv_conf: ~c"/etc/resolv.conf",
res_servfail_retry_timeout: 1500,
res_edns: false,
hostname: ~c"teach-preschool",
res_alt_ns: [],
cache_refresh_interval: 3600000,
res_inet6: false,
res_udp_payload_size: 1280,
socks5_port: 1080,
socks5_methods: [:none],
res_hosts_file_tm: -576460758,
res_timeout: 2000,
cache_size: 100,
res_resolv_conf_tm: -576460758,
res_domain: ~c"hsd1.md.comcast.net",
res_retry: 3,
👉 res_ns: [{{1, 1, 1, 1}, 53}], 👈
res_lookup: [:native],
res_resolv_conf_info: :undefined,
sctp_module: :inet_sctp,
udp_module: :inet_udp,
tcp_module: :inet_tcp,
res_hosts_file_info: :undefined,
socks5_server: [],
res_search: [~c"hsd1.md.comcast.net"],
res_hosts_file: ~c"/etc/hosts",
res_usevc: false
]
- Type
"elixir-lang.org" |> String.to_charlist() |> :inet_res.lookup(:in, :mx, [], 1000)
- Log the ETS table to see how it's changed:
`:ets.tab2list(:inet_db)`
[
socks5_noproxy: [],
res_recurse: true,
res_id: 2,
res_resolv_conf: ~c"/etc/resolv.conf",
res_servfail_retry_timeout: 1500,
res_edns: false,
hostname: ~c"teach-preschool",
res_alt_ns: [],
cache_refresh_interval: 3600000,
res_inet6: false,
res_udp_payload_size: 1280,
socks5_port: 1080,
socks5_methods: [:none],
res_hosts_file_tm: -576460758,
res_timeout: 2000,
cache_size: 100,
res_resolv_conf_tm: -576460690,
res_domain: ~c"hsd1.md.comcast.net",
res_retry: 3,
res_ns: [
👉 {{9729, 333, 20992, 56146, 60063, 33023, 65092, 21823}, 53}, 👈
{{10, 0, 0, 1}, 53}
],
res_lookup: [:native],
res_resolv_conf_info: {:file_info, 431, :regular, :read,
{{2024, 12, 19}, {16, 38, 33}}, {{2024, 12, 19}, {16, 16, 41}},
{{2024, 12, 19}, {16, 16, 41}}, 33188, 1, 16777233, 0, 256879253, 0, 1},
sctp_module: :inet_sctp,
udp_module: :inet_udp,
tcp_module: :inet_tcp,
res_hosts_file_info: :undefined,
socks5_server: [],
res_search: [~c"hsd1.md.comcast.net"],
res_hosts_file: ~c"/etc/hosts",
res_usevc: false
]
To fix this, the db can be reset and the NS added again:
:inet_db.reset()
:inet_db.add_ns({1,1,1,1})
"elixir-lang.org" |> String.to_charlist() |> :inet_res.lookup(:in, :mx, [], 1000)
:ets.tab2list(:inet_db)
Resolved NS are still 1.1.1.1
[
socks5_noproxy: [],
res_recurse: true,
res_id: 1,
res_resolv_conf: ~c"/etc/resolv.conf",
res_servfail_retry_timeout: 1500,
res_edns: false,
hostname: [],
res_alt_ns: [],
cache_refresh_interval: 3600000,
res_inet6: false,
res_udp_payload_size: 1280,
socks5_port: 1080,
socks5_methods: [:none],
res_hosts_file_tm: -576460758,
res_timeout: 2000,
cache_size: 100,
res_resolv_conf_tm: -576459981,
res_domain: [],
res_retry: 3,
👉 res_ns: [{{1, 1, 1, 1}, 53}], 👈
res_lookup: [],
res_resolv_conf_info: {:file_info, 431, :regular, :read,
{{2024, 12, 19}, {16, 38, 33}}, {{2024, 12, 19}, {16, 16, 41}},
{{2024, 12, 19}, {16, 16, 41}}, 33188, 1, 16777233, 0, 256879253, 0, 1},
sctp_module: :inet_sctp,
udp_module: :inet_udp,
tcp_module: :inet_tcp,
res_hosts_file_info: :undefined,
socks5_server: [],
res_search: [],
res_hosts_file: ~c"/etc/hosts",
res_usevc: false
]
Expected behavior
When I set the nameservers for inet, they should not be erased when using inet_res.lookup
Affected versions
This is affecting Elixir 1.17 running on Erlang 25.3.2.16.