Skip to content

Commit

Permalink
only reconnect if we receive EXIT from the conn pid
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Green committed Dec 14, 2018
1 parent 15c042f commit 4d6ebbf
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/pgapp_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ handle_call({transaction, Fun}, _From,
handle_cast(reconnect, State) ->
{noreply, connect(State)}.

handle_info({'EXIT', From, Reason}, State) ->
handle_info({'EXIT', Conn, Reason}, #state{conn=Conn} = State) ->
{NewDelay, Tref} =
case State#state.timer of
undefined ->
Expand All @@ -137,9 +137,12 @@ handle_info({'EXIT', From, Reason}, State) ->
end,

error_logger:warning_msg(
"~p EXIT from ~p: ~p - attempting to reconnect in ~p ms~n",
[self(), From, Reason, NewDelay]),
{noreply, State#state{conn = undefined, delay = NewDelay, timer = Tref}}.
"~p EXIT from epgsql_sock ~p: ~p - attempting to reconnect in ~p ms~n",
[self(), Conn, Reason, NewDelay]),
{noreply, State#state{conn = undefined, delay = NewDelay, timer = Tref}};

handle_info(_Other, State) ->
{noreply, State}.

terminate(_Reason, #state{conn = undefined}) ->
ok;
Expand Down

0 comments on commit 4d6ebbf

Please sign in to comment.