Additional message is sent to process when request times out
I use a timeout of 500ms for a call to an external service.
Sometimes the request times out and that's fine, but then my GenServer recieves a message of the following format. Since I do not handle it, it crashes :(
[error] AdExchange.OpenRTB.V24Worker #PID<0.1658.0> received unexpected message in handle_info/2: {#Reference<0.640795280.3317170178.75561>, {:ok, '200', [{'Date', 'Fri, 23 Feb 2018 16:47:29 GMT'}, {'Content-Type', 'application/json; charset=utf-8'}, {'Server', 'Kestrel'}, {'Transfer-Encoding', 'chunked'}], '<some_json_result>''}}
Seems like it sends the result, when I don't need it anymore.
I read docs, and I am not using async requests for sure.
Is this an expected behaviour?
HTTPotion is 3.1.0.
Hi. That's weird. HTTPotion would never send something that looks like {:ok, …} — async responses are %HTTPotion.AsyncSomething{…}. { :ok, status_code, headers, body } is the format of synchronous responses from ibrowse, which is handled in handle_response.
How does the request call look like?
This is how I send and handle response.
defp request(encoded_obj, url, apikey) when is_bitstring(encoded_obj) do
headers =
if apikey,
do: [{"Content-Type", "application/json"}, {"apikey", apikey}],
else: [{"Content-Type", "application/json"}]
options = [body: encoded_obj, timeout: @timeout, body: encoded_obj, headers: headers]
url
|> HTTPotion.post(options)
|> handle_response()
end
defp request(nil, _url, _apikey) do
{:error, :nil_request}
end
defp handle_response(%HTTPotion.Response{status_code: 200, body: body}) do
{:ok, Helper.decode!(body)}
end
defp handle_response(%HTTPotion.Response{status_code: 204}) do
{:error, :empty_result}
end
defp handle_response(%HTTPotion.Response{status_code: 403}) do
{:error, :unauthorized}
end
defp handle_response(%HTTPotion.ErrorResponse{message: message}) do
{:error, message}
end
defp handle_response(resp) do
Logger.warn("Unkown response received: #{inspect(resp)}")
{:error, :unknown_response}
end
I know it shouldn't, but the data in message looks like it comes from there. And I did not see this error before, until now that I switched to HTTPotion.
I'm still having this issue. Any idea on how can I track this?
There are many debugging tools. I don't know which is the best one.
I'm having the same issue. My Genserver crashes because it sometimes receives an unhandled message from HTTPotion.
It seems this issue comes from ibrowse. See the following ticket: https://github.com/cmullaparthi/ibrowse/issues/36