My favorites | Sign in
Project Logo
                
New issue | Search
for
| Advanced search | Search tips
Issue 15: [PATCH] Resolving maildomain is very very very slow
1 person starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  ----
Closed:  Sep 2008
Type-Defect
Priority-Medium


Sign in to add a comment
 
Reported by jos.i.boumans, Sep 07, 2008
Im using T::R 1.51_01 on perl 5.8.8.

On my machine, resolving the ->from address ends up calling Net::SMTP->new for a few 
mailhosts to determine my maildomain. Since the timeout per call is 120 seconds, this is a very 
lengthy process.

The attached patch does a few things:

1) It caches the result of the ->_maildomain() call
2) It lowers the timeout for Net::SMTP->new from 120 seconds to 5 seconds
3) It adds the host 'smtp' to check for a maildomain
4) 1.51_01 does not return a 'true' value at the end of file (there's an __END__ marker before the 
end)

For clarity, I've omitted whitespace changes (since this does a block indent). You may want
to add that yourself to suit your coding style.

$ diff -dwu lib/Test//Reporter.pm.org lib/Test/Reporter.pm
--- lib/Test//Reporter.pm.org   2008-09-07 15:02:01.000000000 +0200
+++ lib/Test/Reporter.pm        2008-09-07 15:35:25.000000000 +0200
@@ -563,11 +563,15 @@
 }
 
 # From Mail::Util 1.74 (c) 1995-2001 Graham Barr (c) 2002-2005 Mark Overmeer
+{   # cache the result of this, so we don't try to resolve this *every*
+    # iteration -kane
+    my $domain;     
+
 sub _maildomain {
     my $self = shift;
     warn __PACKAGE__, ": _maildomain\n" if $self->debug();
 
-    my $domain = $ENV{MAILDOMAIN};
+        $domain = $ENV{MAILDOMAIN} if defined $ENV{MAILDOMAIN};
 
     return $domain if defined $domain;
 
@@ -616,8 +620,12 @@
     if (eval {require Net::SMTP}) {
         my $host;
 
-        for $host (qw(mailhost localhost)) {
-            my $smtp = eval {Net::SMTP->new($host)};
+            for $host (qw(mailhost smtp localhost)) {
+            
+                # default timeout is 120, which is Very Very Long, so lower
+                # it to 5 seconds. Total slowdown will not be more than
+                # 15 seconds ( 5 x @hosts ) --kane
+                my $smtp = eval {Net::SMTP->new($host, Timeout => 5)};
 
             if (defined $smtp) {
                 $domain = $smtp->domain;
@@ -643,6 +651,7 @@
 
     return $domain;
 }
+}
 
 # From Mail::Util 1.74 (c) 1995-2001 Graham Barr (c) 2002-2005 Mark Overmeer
 sub _mailaddress {
@@ -689,6 +698,9 @@
     return $perl =~ /^perl-?\d\.\d/;
 }
 
+# need a true value
+1;
+
 __END__
 
 =head1 NAME
 
Comment 1 by xdaveg, Sep 07, 2008
Thanks.  Applied, tweaked and released as 1.51_02
Status: Fixed
Sign in to add a comment

Hosted by Google Code