Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional message is sent to process when request times out #121

Open
vfsoraki opened this issue Feb 23, 2018 · 5 comments
Open

Additional message is sent to process when request times out #121

vfsoraki opened this issue Feb 23, 2018 · 5 comments

Comments

@vfsoraki
Copy link

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.

@valpackett
Copy link
Owner

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?

@vfsoraki
Copy link
Author

vfsoraki commented Feb 23, 2018

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.

@vfsoraki
Copy link
Author

vfsoraki commented Mar 4, 2018

I'm still having this issue. Any idea on how can I track this?

@valpackett
Copy link
Owner

There are many debugging tools. I don't know which is the best one.

@philipgiuliani
Copy link

philipgiuliani commented Jun 14, 2018

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: cmullaparthi/ibrowse#36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants