:httpoison does not get started

Hi all
I want to use httpoison on my phoenix app and got following error:


It seems to be, that the httpoison process does not get started.

In the mix.exs file, I do start the httpoison process:

  def application do
    [mod: {Northwind, []},
     applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext, :httpoison]]
  end

What am I doing wrong?

Thanks

Are you sure it is :httpoison that has not been started? The stacktrace is complaining about :hackney.

Please post the output of MIX_ENV=prod mix app.tree as well as MIX_ENV=dev mix app.tree (just to be sure).

Also please try to verify using :observer if or if not hackney and httpoison have been started.

What is MIX_ENV=prod mix app.tree and MIX_ENV=dev mix app.tree and how can I get the output of it?

The whole mix file:

defmodule Northwind.Mixfile do
  use Mix.Project

  def project do
    [app: :northwind,
     version: "0.0.1",
     elixir: "~> 1.2",
     elixirc_paths: elixirc_paths(Mix.env),
     compilers: [:phoenix, :gettext] ++ Mix.compilers,
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     deps: deps()]
  end

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [mod: {Northwind, []},
     applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext, :httpoison]]
  end

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "web", "test/support"]
  defp elixirc_paths(_),     do: ["lib", "web"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [{:phoenix, "~> 1.2.1"},
     {:phoenix_pubsub, "~> 1.0"},
     {:phoenix_html, "~> 2.6"},
     {:phoenix_live_reload, "~> 1.0", only: :dev},
     {:gettext, "~> 0.11"},
     {:cowboy, "~> 1.0"},
     {:poison, "~> 3.0", override: true},
     {:httpoison, "~> 0.10.0"}]
  end
end

Thanks

That are commands you were supposed to enter into your terminal, but I assumed a linux environment. For windows I am not sure how to set an environment variable only for a single command, you might need to do it the hardway:

$ set MIX_ENV_OLD=%MIX_ENV%
$ set MIX_ENV=prod
$ mix app.tree
$ set MIX_ENV=dev
$ mix app.tree
$ set MIX_ENV=%MIX_ENV_OLD%

run these commands in a command prompt (Eingabeaufforderung) which is in the project folder of application.


But you are right, from the :observer-screen you posted, there is neither :hackney nor :httpoison started.

How do you start your application?

With

:\phoenix\northwind>iex -S mix phoenix.server
Eshell V8.1  (abort with ^G)
[info] Running Northwind.Endpoint with Cowboy using http://localhost:4000
Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :observer.start
:ok
iex(2)>

The output of app.tree

D:\phoenix\northwind>set "MIX_ENV=dev" && mix compile

D:\phoenix\northwind>mix app.tree
northwind
|-- elixir
|-- phoenix
|   |-- elixir
|   |-- plug
|   |   |-- elixir
|   |   |-- crypto
|   |   |-- logger
|   |   |   `-- elixir
|   |   `-- mime
|   |       `-- elixir
|   |-- poison
|   |   `-- elixir
|   |-- logger
|   `-- eex
|       `-- elixir
|-- phoenix_pubsub
|   |-- elixir
|   |-- logger
|   `-- crypto
|-- phoenix_html
|   |-- elixir
|   |-- logger
|   `-- plug
|-- cowboy
|   |-- ranch
|   |-- cowlib
|   |   `-- crypto
|   `-- crypto
|-- logger
`-- gettext
    |-- elixir
    `-- logger

As a test, what if you add :hackney to your applications dependency list?

OK, I took a deeper look into :httpoison, it seems as if it hasn’t been written properly and relies on beeing started manually.

You should have a Northwind.start/2 function, please add HTTPoison.start into it and report back if it works then.

I just clean everything with mix clean --all and then start the server again.

Thanks for helping.

Out of curiosity, what’s wrong w/ how HTTPoison has set things up? I’ve been having the same problems with it, and would be willing to send them a PR, if I knew generally where to get started.

1 Like

I’m not sure if I’d call it beeing the wrong way, but at least, its a not so common way in the BEAM world. If your app needs to have a proper supervision tree or workers set up, then do this in the application initialisation phase.

It is common sense that an app is not responsive until fully started and often one doesn’t care if it takes one or five seconds or even a minute until an application gets responsive. But if you need to check and perhaps start httpoison on first request that needs it, you might miss your response window.

The only way to ensure httpoison is started when needed is by starting it manually in your application start callback.

But BEAM has already the necessary tools to do this automatically, AFAIK all the guys at httpoison needs to do is to alter the application/0-function in the mixfile a bit:

def application do
  [mod: {HTTPoison, []}, applications: [:hackney]]
end

Only by adding mod: {HTTPoison, []}, the BEAM does know that this is actually an application which needs to get started or that has a dependency that needs to be startet.

2 Likes