dovecot-2.0: config: Abort local/remote block DNS lookups after ...

dovecot at dovecot.org dovecot at dovecot.org
Wed Apr 13 12:23:37 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/cf9c2252a3ea
changeset: 12744:cf9c2252a3ea
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Apr 13 12:23:35 2011 +0300
description:
config: Abort local/remote block DNS lookups after 30s and warn after 5s.

diffstat:

 src/config/config-parser.c |  14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diffs (53 lines):

diff -r b60d73301c08 -r cf9c2252a3ea src/config/config-parser.c
--- a/src/config/config-parser.c	Wed Apr 13 10:36:00 2011 +0300
+++ b/src/config/config-parser.c	Wed Apr 13 12:23:35 2011 +0300
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <time.h>
 #ifdef HAVE_GLOB_H
 #  include <glob.h>
 #endif
@@ -27,6 +28,9 @@
 #  define GLOB_BRACE 0
 #endif
 
+#define DNS_LOOKUP_TIMEOUT_SECS 30
+#define DNS_LOOKUP_WARN_SECS 5
+
 static const enum settings_parser_flags settings_parser_flags =
 	SETTINGS_PARSER_FLAG_IGNORE_UNKNOWN_KEYS |
 	SETTINGS_PARSER_FLAG_TRACK_CHANGES;
@@ -209,6 +213,7 @@
 	struct ip_addr *ips;
 	const char *p;
 	unsigned int ip_count, bits, max_bits;
+	time_t t1, t2;
 	int ret;
 
 	if (net_parse_range(value, ip_r, bits_r) == 0)
@@ -220,7 +225,11 @@
 		p++;
 	}
 
+	t1 = time(NULL);
+	alarm(DNS_LOOKUP_TIMEOUT_SECS);
 	ret = net_gethostbyname(value, &ips, &ip_count);
+	alarm(0);
+	t2 = time(NULL);
 	if (ret != 0) {
 		*error_r = t_strdup_printf("gethostbyname(%s) failed: %s",
 					   value, net_gethosterror(ret));
@@ -228,6 +237,11 @@
 	}
 	*ip_r = ips[0];
 
+	if (t2 - t1 >= DNS_LOOKUP_WARN_SECS) {
+		i_warning("gethostbyname(%s) took %d seconds",
+			  value, (int)(t2-t1));
+	}
+
 	max_bits = IPADDR_IS_V4(&ips[0]) ? 32 : 128;
 	if (p == NULL || str_to_uint(p, &bits) < 0 || bits > max_bits)
 		*bits_r = max_bits;


More information about the dovecot-cvs mailing list