Found this on stackoverflow for resolving the issue in Ruby:
It seems to be a problem with certain versions of libc which resolve DNS routes. After spending couple hours to search solution you just need to add
require 'resolv-replace'at the beginning of your code.More information: Use Ruby DNS resolver to handle DNS timeout in Net::HTTP by pranas · Pull Request #597 · ruby/ruby · GitHub
Hope this help somebody in the future.