Skip to content

Commit

Permalink
Merge pull request wooga#93 from ololoru/reconnect_loop_race
Browse files Browse the repository at this point in the history
fix reconnect loop race condition
  • Loading branch information
knutin authored Aug 15, 2017
2 parents b03c27c + 1f292f6 commit b0ff5a9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/eredis_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,10 @@ do_sync_command(Socket, Command) ->
reconnect_loop(Client, #state{reconnect_sleep = ReconnectSleep} = State) ->
case catch(connect(State)) of
{ok, #state{socket = Socket}} ->
Client ! {connection_ready, Socket},
gen_tcp:controlling_process(Socket, Client),
Client ! {connection_ready, Socket};
Msgs = get_all_messages([]),
[Client ! M || M <- Msgs];
{error, _Reason} ->
timer:sleep(ReconnectSleep),
reconnect_loop(Client, State);
Expand All @@ -376,3 +378,12 @@ read_database(undefined) ->
undefined;
read_database(Database) when is_integer(Database) ->
list_to_binary(integer_to_list(Database)).


get_all_messages(Acc) ->
receive
M ->
[M | Acc]
after 0 ->
lists:reverse(Acc)
end.

0 comments on commit b0ff5a9

Please sign in to comment.