]> granicus.if.org Git - ejabberd/commitdiff
Fix s2s_dns_timeout issues
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 20 Feb 2017 07:42:16 +0000 (10:42 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 20 Feb 2017 07:42:16 +0000 (10:42 +0300)
src/ejabberd_s2s_out.erl
src/xmpp_stream_out.erl

index 614da2325cd9a6a188519f0dff7c7a1464ac3a4d..909177266537c7e5fdde6abcca8201216e85315e 100644 (file)
@@ -404,7 +404,7 @@ transform_options({s2s_dns_options, S2SDNSOpts}, AllOpts) ->
 transform_options({Opt, T}, Opts)
   when Opt == outgoing_s2s_timeout; Opt == s2s_dns_timeout ->
     maybe_report_huge_timeout(Opt, T),
-    [{outgoing_s2s_timeout, T}|Opts];
+    [{Opt, T}|Opts];
 transform_options(Opt, Opts) ->
     [Opt|Opts].
 
index 0843780f6bb69651d3b93ddcdcb0f375c2efbbfc..5efc940c218521eb5295ac51df98d67fa342eb3f 100644 (file)
@@ -886,9 +886,20 @@ a_lookup([], _State, Err) ->
 a_lookup(_Host, _Port, _Family, _Timeout, Retries) when Retries < 1 ->
     {error, timeout};
 a_lookup(Host, Port, Family, Timeout, Retries) ->
+    Start = p1_time_compat:monotonic_time(milli_seconds),
     case inet:gethostbyname(Host, Family, Timeout) of
-       {error, timeout} ->
-           a_lookup(Host, Port, Family, Timeout, Retries - 1);
+       {error, nxdomain} = Err ->
+           %% inet:gethostbyname/3 doesn't return {error, timeout},
+           %% so we should check if 'nxdomain' is in fact a result
+           %% of a timeout.
+           %% We also cannot use inet_res:gethostbyname/3 because
+           %% it ignores DNS configuration settings (/etc/hosts, etc)
+           End = p1_time_compat:monotonic_time(milli_seconds),
+           if (End - Start) >= Timeout ->
+                   a_lookup(Host, Port, Family, Timeout, Retries - 1);
+              true ->
+                   Err
+           end;
        {error, _} = Err ->
            Err;
        {ok, HostEntry} ->