Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inet_res.lookup resets the resolved nameservers in inet_db #9224

Open
scottmessinger opened this issue Dec 20, 2024 · 1 comment
Open

inet_res.lookup resets the resolved nameservers in inet_db #9224

scottmessinger opened this issue Dec 20, 2024 · 1 comment
Assignees
Labels
bug Issue is reported as a bug team:PS Assigned to OTP team PS waiting waiting for changes/input from author

Comments

@scottmessinger
Copy link

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

  1. 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
]
  1. Type "elixir-lang.org" |> String.to_charlist() |> :inet_res.lookup(:in, :mx, [], 1000)
  2. 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.

@RaimoNiskanen
Copy link
Contributor

Hello Scott, I use Erlang, so I will answer in Erlang, sorry about that.

When I start a default node, and run inet_db:get_rc() I get the default config:

Eshell V15.0 (press Ctrl+G to abort, type help(). for help)
1> inet_db:get_rc().
[{dnssec_ok,undefined},
 {resolv_conf,"/etc/resolv.conf"},
 {hosts_file,"/etc/hosts"},
 {lookup,[native]}]

The resolv_conf option set to "/etc/resolv.conf" means that that file will be monitored, and when it changes, (inet_res checks the file time stamp before every query) the content is read and the nameservers and search options are be updated from the file content.

You may add more name servers using inet_db:add_alt_ns/1,2 that are not auto updated, but that doesn't get rid of any slow nameservers in the primary list, which are tried first.

You can disable this auto update function by setting the resolv_conf file name to "" with inet_db:set_resolv_conf(""), and then you will have to set and update the name servers and search domain at your own discretion.

@IngelaAndin IngelaAndin added the waiting waiting for changes/input from author label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:PS Assigned to OTP team PS waiting waiting for changes/input from author
Projects
None yet
Development

No branches or pull requests

3 participants