Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Add a code_change clause for DNS TTL additions
Browse files Browse the repository at this point in the history
BugzID: 41419
  • Loading branch information
b20n committed Nov 24, 2014
1 parent ad6476d commit d99c1a4
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/couch_replicator_httpc_pool.erl
Expand Up @@ -12,7 +12,7 @@

-module(couch_replicator_httpc_pool).
-behaviour(gen_server).
-vsn(1).
-vsn(2).

% public API
-export([start_link/2, stop/1]).
Expand Down Expand Up @@ -139,6 +139,33 @@ handle_info(refresh_dns, State0) ->
{noreply, State1}.


code_change(1, OldState, _Extra) ->
{state, Url, Limit, Free, Busy, Waiting, Callers} = OldState,
State0 = case couch_replicator_dns:lookup(Url) of
{ok, {Data, TTL}} ->
timer:send_after(TTL * 1000, refresh_dns),
#state{
dns_data = Data,
dns_ttl = TTL
};
{error, Error} ->
twig:log(
warn,
"couch_replicator_httpc_pool failed DNS lookup: ~p",
[Error]
),
#state{}
end,
State1 = State0#state{
url = Url,
limit = Limit,
free = Free,
busy = Busy,
waiting = Waiting,
callers = Callers
},
{ok, State1};

code_change(_OldVsn, #state{}=State, _Extra) ->
{ok, State}.

Expand Down

0 comments on commit d99c1a4

Please sign in to comment.