Browse Source

fix bug with reconnect

Yuriy Zhloba 9 years ago
parent
commit
d59b32319d
2 changed files with 10 additions and 3 deletions
  1. 3 1
      .gitignore
  2. 7 2
      src/epgsql_pool_worker.erl

+ 3 - 1
.gitignore

@@ -6,4 +6,6 @@ deps/
 logs
 logs
 erl_crash.dump
 erl_crash.dump
 _build
 _build
-rebar.lock
+rebar.lock
+.idea
+*.iml

+ 7 - 2
src/epgsql_pool_worker.erl

@@ -151,12 +151,17 @@ handle_info({'EXIT', _Sock, normal},
     {noreply, State};
     {noreply, State};
 
 
 handle_info({'EXIT', Sock, Reason},
 handle_info({'EXIT', Sock, Reason},
-            #state{connection = #epgsql_connection{sock = Sock} = Connection} = State) ->
-    error_logger:error_msg("DB Connection ~p EXIT with reason: ~p", [Sock, Reason]),
+    #state{connection = #epgsql_connection{sock = Sock} = Connection} = State) ->
+    error_logger:error_msg("DB Connection ~p~nEXIT with reason:~p", [Connection, Reason]),
     Connection2 = epgsql_pool_utils:close_connection(Connection),
     Connection2 = epgsql_pool_utils:close_connection(Connection),
     Connection3 = epgsql_pool_utils:reconnect(Connection2),
     Connection3 = epgsql_pool_utils:reconnect(Connection2),
     {noreply, State#state{connection = Connection3}};
     {noreply, State#state{connection = Connection3}};
 
 
+handle_info({'EXIT', _Sock, econnrefused},
+    #state{connection = #epgsql_connection{sock = undefined}} = State) ->
+    %% reconnect is already running, do nothing
+    {noreply, State};
+
 handle_info(Message, State) ->
 handle_info(Message, State) ->
     error_logger:error_msg("unknown info ~p in ~p ~n", [Message, ?MODULE]),
     error_logger:error_msg("unknown info ~p in ~p ~n", [Message, ?MODULE]),
     {noreply, State}.
     {noreply, State}.