DNS resolution should fall back to TCP on Errno::EACCES
On some platforms, users may be restricted from global binding to a UDP port, which is necessary for UDP-based DNS lookups. In this case, an exception like the following is currently raised:
ruby -r resolv -e 'puts Resolv.getaddress "'
bind': Permission denied - bind(2) (Errno::EACCES)bind_random_port'
each_address'block in each_address'
This error should be caught, and the resolver should fall back to TCP, as it does in other cases where this is necessary. A possible patch for this (written against 2.0.0p353 in RHEL) is attached.
Ideally, it would also be nice to be able to specify tcp by default when initializing a DNS object on such platforms, to avoid repeated bind attempts which are known to fail, but I am not sure of the best way to introduce such an option.
Updated by jeremyevans0 (Jeremy Evans) about 2 years ago
- Assignee set to akr (Akira Tanaka)
- Status changed from Open to Assigned
- File resolv-tcp-fallback-eacces.patch resolv-tcp-fallback-eacces.patch added
I'm not sure I would consider this a bug, but it seems like a reasonable change. Attached is an updated patch that applies against master.