tsloughter / erlastic_search

An Erlang app for communicating with Elastic Search's rest interface.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blocking request issue

arkanmgerges opened this issue · comments

Hi,
I'm currently using this app in my production code, I had an issue with blocking requests. I have a timeout returned from init() to be handled in to handle_info(), and from there I'm casting a request with gen_server:cast() to be handled into handle_cast().
Inside I'm calling a function that has this code snippet:
try erlastic_search:search_limit(<<"message">>, <<"inbox">>, <<<<"userId:">>/binary, A/binary, "&_source=''">>, 9999) of
{ok, Resp} ->
{<<"hits">>, Hits} = lists:keyfind(<<"hits">>, 1, Resp),
{<<"hits">>, Hits1} = lists:keyfind(<<"hits">>, 1, Hits),
parse_es_response_data_to_id_list(Hits1);
_ -> []
catch
: -> []
end.

First time this code will work, but then it will not work, I think there is something related to Hackney, I'm not sure.
Currently I solved the issue by adding error() before {noreply, State} inside handle_cast(), and now the code is working on production:

handle_cast({disableMessages, UserId}, State) ->
IdList = fetch_msg_id_list_for(UserId),
set_msg_availability(IdList, <<"false">>),
error(break_blocking), <------------------------ this solved my issue
{noreply, State};

Thanks for your time and effort for providing libraries and applications for the Erlang community.