From d99c1a4a6df8d7ae31f09821265458cc7bd4a3ee Mon Sep 17 00:00:00 2001 From: Benjamin Anderson Date: Mon, 24 Nov 2014 15:42:16 -0800 Subject: [PATCH] Add a code_change clause for DNS TTL additions BugzID: 41419 --- src/couch_replicator_httpc_pool.erl | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/couch_replicator_httpc_pool.erl b/src/couch_replicator_httpc_pool.erl index 94d6496..affbcd3 100644 --- a/src/couch_replicator_httpc_pool.erl +++ b/src/couch_replicator_httpc_pool.erl @@ -12,7 +12,7 @@ -module(couch_replicator_httpc_pool). -behaviour(gen_server). --vsn(1). +-vsn(2). % public API -export([start_link/2, stop/1]). @@ -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}.