eredis
eredis copied to clipboard
get_all_messages only gets one message?
If get_all_messages might receive more than one message, I think it should be changed to:
get_all_messages(Acc) ->
receive
M ->
get_all_messages([M | Acc])
after 0 ->
lists:reverse(Acc)
end.
I think there is still a possible race condition.
- We call Client ! {connection_ready, Socket}.
- Client receive a redis command waiting in the mailbox.
- [Client ! M || M <- Msgs] is called with tcp_closed message.
Maybe we should send connection_ready only if Msgs is empty?
reconnect_loop(Client, #state{reconnect_sleep = ReconnectSleep} = State) ->
case catch(connect(State)) of
{ok, #state{socket = Socket}} ->
gen_tcp:controlling_process(Socket, Client),
case get_all_messages([]) of
[] ->
Client ! {connection_ready, Socket};
_ ->
timer:sleep(ReconnectSleep),
reconnect_loop(Client, State);
{error, _Reason} ->
timer:sleep(ReconnectSleep),
reconnect_loop(Client, State);
%% Something bad happened when connecting, like Redis might be
%% loading the dataset and we got something other than 'OK' in
%% auth or select
_ ->
timer:sleep(ReconnectSleep),
reconnect_loop(Client, State)
end.