Starting hackney so I can use it in runtime.exs

Hello, I would like to do a http request to Vault during runtime.exs . I am using Httpoison, but same result for Tesla, everything works fine to get the Vault key when using the module directly in an iex session, but when putting the code in runtime.exs I get the following error:

** (ArgumentError) errors were found at the given arguments:

  • 1st argument: the table identifier does not refer to an existing ETS table
    (stdlib 3.16.1) :ets.lookup_element(:hackney_config, :mod_metrics, 2)

From my understanding the hackney process needs to be started which is done automatically as it is one of deps, however that process only kicks in after runtime.exs is processed. My question is how do I start hackney correctly before runtime.exs ? I tried adding to extra_applications: in mix.exs but that does not seem to do the trick.

For that usecase you should consider a custom config provider:

https://hexdocs.pm/elixir/Config.Provider.html#module-custom-config-provider

2 Likes

Thank you, yes after reading the docs I agree that seems the best way to move forward. Thanks for pointing that out :smiley:

Config providers are probably a better approach - but I think I have solved this by simple running Application.ensure_all_started/2 or possibly Application.ensure_started/2 earlier in the runtime.exs file.

Like this:
:ok = Application.ensure_all_started(:hackney)

Application — Elixir v1.12.3 (hexdocs.pm)

2 Likes