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

Shorten timeout for DNS lookups #66

Closed
aripollak opened this issue Jan 5, 2017 · 3 comments · Fixed by #76
Closed

Shorten timeout for DNS lookups #66

aripollak opened this issue Jan 5, 2017 · 3 comments · Fixed by #76

Comments

@aripollak
Copy link

aripollak commented Jan 5, 2017

The default timeout for Resolv::DNS results in the validation for an unresponsive domain (like test123.com) taking at least 20 seconds. I'd like to reduce the timeout in validates_email_format_of using this since 20 seconds is way too long for a web request. Would you be okay with reducing the default timeout to 2 seconds with no retries (that would end up being 4 seconds total, one for A and one for MX)? Alternatively, validates_email_format_of can take an optional timeout number.

@fluke
Copy link

fluke commented Feb 13, 2017

It should be a simple change. This function needs to take timeouts as well and we can have timeouts as an option to validates_email_format_of.

def self.validate_email_domain(email)

def self.validate_email_domain(email, timeouts = 2)
    domain = email.to_s.downcase.match(/\@(.+)/)[1]
    Resolv::DNS.open do |dns|
        dns.timeouts = timeouts
        @mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) + dns.getresources(domain, Resolv::DNS::Resource::IN::A)
    end
    @mx.size > 0 ? true : false
end

@atomical
Copy link

If it times out does it return invalid for the e-mail?

@alexdunae
Copy link
Contributor

Good idea. I've added that.

If it times out a ResolvTimeout is thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants