How to use pheonix with TLS and Erlang 24?

How do I fix problems as explained by: TLS connections fail with OTP-24 (in one project only)?

I get timeout errors from the client when trying to access the server, and since I have also seen the same error I believe it to be the same problem.

The suggested solution is to upgrade ranch:

mix deps.get
Resolving Hex dependencies...

Failed to use "ranch" (version 2.0.0) because
  cowboy (version 2.9.0) requires 1.8.0
  mix.exs specifies ~> 2.0

** (Mix) Hex dependency resolution failed, change the version requirements of your dependencies or unlock them (by using mix deps.update or mix deps.unlock). If you are unable to resolve the conflicts you can try overriding with {:dependency, "~> 1.0", override: true}

But that fails. I believe I have the latest version of plug_cowboy (2.5.0) which depends on the latest version of cowboy (2.9.0) which depends on an outdated version of ranch (1.8.0), which doesn’t work with erlang 24.

I tried adding the required override, but the server won’t even start then.

22:43:24.122 [info]  Application robotica_face exited: RoboticaFace.Application.start(:normal, []) returned an error: shutdown: failed to start child: RoboticaFaceWeb.Endpoint
    ** (EXIT) an exception was raised:
        ** (MatchError) no match of right hand side value: %{id: {:ranch_embedded_sup, RoboticaFaceWeb.Endpoint.HTTP}, start: {:ranch_embedded_sup, :start_link, [RoboticaFaceWeb.Endpoint.HTTP, :ranch_tcp, %{max_connections: 16384, num_acceptors: 100, socket_opts: [port: 4000, ip: {0, 0, 0, 0, 0, 0, 0, 0}]}, :cowboy_clear, %{env: %{dispatch: [{:_, [], [{:_, [], Phoenix.Endpoint.Cowboy2Handler, {RoboticaFaceWeb.Endpoint, []}}]}]}, stream_handlers: [:cowboy_telemetry_h, :cowboy_stream_h]}]}, type: :supervisor}
            (plug_cowboy 2.4.1) lib/plug/cowboy.ex:207: Plug.Cowboy.child_spec/1
            (phoenix 1.5.8) lib/phoenix/endpoint/cowboy2_adapter.ex:84: Phoenix.Endpoint.Cowboy2Adapter.child_spec/3
            (phoenix 1.5.8) lib/phoenix/endpoint/cowboy2_adapter.ex:64: anonymous fn/5 in Phoenix.Endpoint.Cowboy2Adapter.child_specs/2
            (elixir 1.12.1) lib/enum.ex:2356: Enum."-reduce/3-lists^foldl/2-0-"/3
            (phoenix 1.5.8) lib/phoenix/endpoint/cowboy2_adapter.ex:55: Phoenix.Endpoint.Cowboy2Adapter.child_specs/2
            (phoenix 1.5.8) lib/phoenix/endpoint/supervisor.ex:106: Phoenix.Endpoint.Supervisor.init/1
            (stdlib 3.15.1) supervisor.erl:330: :supervisor.init/1
            (stdlib 3.15.1) gen_server.erl:423: :gen_server.init_it/2

Which looks like cowboy is expecting a tuple, but ranch is providing a map.

How do I fix? Downgrade to Erlang 23? Any other options?

Oh wait, found the problem:

Upgraded:
  cowboy 2.8.0 => 2.9.0
  cowlib 2.9.1 => 2.11.0
  mime 1.5.0 => 1.6.0
  plug_cowboy 2.4.1 => 2.5.0
  plug_crypto 1.2.1 => 1.2.2
  telemetry 0.4.2 => 0.4.3

I find elxiir dependancies confusing at times. In this case I have an application robotica_face that that had the updated dependencies. This application is used by robotica_nerves which had the old version. But never “mix deps.outdated” where showing me the problem or “deps.get” was trying to gix the problem.

This doesn’t show plug_cowboy 2.4.1 as being out of date.

> MIX_TARGET=rpi3 mix hex.outdated            
Dependency           Current  Latest  Status               
credo                1.5.6    1.5.6   Up-to-date           
dialyxir             1.1.0    1.1.0   Up-to-date           
dns                  2.2.0    2.3.0   Update not possible  
nerves               1.7.8    1.7.8   Up-to-date           
nerves_init_gadget   0.7.0    0.7.0   Up-to-date           
nerves_network       0.5.5    0.5.5   Up-to-date           
nerves_runtime       0.11.4   0.11.4  Up-to-date           
nerves_time          0.4.2    0.4.2   Up-to-date           
phoenix_live_reload  1.3.1    1.3.3   Update possible      
ring_logger          0.8.2    0.8.2   Up-to-date           
robotica_rpi3        1.16.1   1.16.1  Up-to-date           
shoehorn             0.7.0    0.7.0   Up-to-date           
toolshed             0.2.19   0.2.20  Update possible      

Run `mix hex.outdated APP` to see requirements for a specific dependency.

To view the diffs in each available update, visit:
https://hex.pm/l/vZAuu

This doesn’t upgrade plug_cowboy 2.4.1 despite the fact the dependency has plug_cowboy 2.5.0 in its mix.lock file. But then again maybe mix.lock file of dependencies are not used. Not sure here.

MIX_TARGET=rpi3 mix deps.get                
Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
  bunt 0.2.0
  castore 0.1.9
  certifi 2.6.1
  circular_buffer 0.4.0
  combine 0.10.0
  cowboy 2.8.0
  cowboy_telemetry 0.3.1
  cowlib 2.9.1
  credo 1.5.6
  dialyxir 1.1.0
  dns 2.2.0
  elixir_make 0.6.2
  erlex 0.2.6
  event_bus 1.6.2
  file_system 0.2.10
  font_metrics 0.3.1
  gen_state_machine 3.0.0
  gettext 0.18.2
  hackney 1.17.4
  idna 6.1.1
  input_event 0.4.1
  jason 1.2.2
  joken 2.3.0
  joken_jwks 1.4.1
  jose 1.11.1
  mdns 1.0.12
  metrics 1.0.1
  mime 1.5.0
  mimerl 1.2.0
  mint 1.2.1
  mojito 0.7.7
  msgpax 2.3.0
  muontrap 0.6.0
  nerves 1.7.8
  nerves_firmware_ssh 0.4.6
  nerves_init_gadget 0.7.0
  nerves_network 0.5.5
  nerves_network_interface 0.4.6
  nerves_runtime 0.11.4
  nerves_system_br 1.16.1
  nerves_time 0.4.2
  nerves_toolchain_armv7_nerves_linux_gnueabihf 1.4.3
  nerves_toolchain_ctng 1.8.4
  nerves_wpa_supplicant 0.5.2
  one_dhcpd 0.2.5
  parse_trans 3.3.1
  phoenix 1.5.8
  phoenix_html 2.14.3
  phoenix_live_reload 1.3.1
  phoenix_live_view 0.15.4
  phoenix_pubsub 2.0.0
  plug 1.11.1
  plug_cowboy 2.4.1
  plug_crypto 1.2.1
  poison 4.0.1
  poolboy 1.5.2
  qex 0.5.0
  ranch 2.0.0
  ring_logger 0.8.2
  robotica_rpi3 1.16.1
  scenic 0.10.3
  scenic_driver_nerves_rpi 0.10.1
  scenic_driver_nerves_touch 0.10.0
  shoehorn 0.7.0
  socket 0.3.13
  ssl_verify_fun 1.1.6
  system_registry 0.8.2
  telemetry 0.4.2
  tesla 1.4.0
  timex 3.7.5
  toolshed 0.2.19
  tortoise 0.9.8
  tzdata 1.1.0
  uboot_env 0.3.0
  unicode_util_compat 0.7.0
  yamerl 0.8.1
  yaml_elixir 2.7.0

Nerves environment
  MIX_TARGET:   rpi3
  MIX_ENV:      dev

==> nerves
==> robotica_nerves
Resolving Nerves artifacts...
  Cached robotica_rpi3
  Cached nerves_toolchain_armv7_nerves_linux_gnueabihf

To fix it, I had to use:

X_TARGET=rpi3 mix deps.update plug_cowboy 
Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
  bunt 0.2.0
  castore 0.1.9
  certifi 2.6.1
  circular_buffer 0.4.0
  combine 0.10.0
  cowboy_telemetry 0.3.1
  credo 1.5.6
  dialyxir 1.1.0
  dns 2.2.0
  elixir_make 0.6.2
  erlex 0.2.6
  event_bus 1.6.2
  file_system 0.2.10
  font_metrics 0.3.1
  gen_state_machine 3.0.0
  gettext 0.18.2
  hackney 1.17.4
  idna 6.1.1
  input_event 0.4.1
  jason 1.2.2
  joken 2.3.0
  joken_jwks 1.4.1
  jose 1.11.1
  mdns 1.0.12
  metrics 1.0.1
  mimerl 1.2.0
  mint 1.2.1
  mojito 0.7.7
  msgpax 2.3.0
  muontrap 0.6.0
  nerves 1.7.8
  nerves_firmware_ssh 0.4.6
  nerves_init_gadget 0.7.0
  nerves_network 0.5.5
  nerves_network_interface 0.4.6
  nerves_runtime 0.11.4
  nerves_system_br 1.16.1
  nerves_time 0.4.2
  nerves_toolchain_armv7_nerves_linux_gnueabihf 1.4.3
  nerves_toolchain_ctng 1.8.4
  nerves_wpa_supplicant 0.5.2
  one_dhcpd 0.2.5
  parse_trans 3.3.1
  phoenix 1.5.8
  phoenix_html 2.14.3
  phoenix_live_reload 1.3.1
  phoenix_live_view 0.15.4
  phoenix_pubsub 2.0.0
  plug 1.11.1
  poison 4.0.1
  poolboy 1.5.2
  qex 0.5.0
  ranch 2.0.0
  ring_logger 0.8.2
  robotica_rpi3 1.16.1
  scenic 0.10.3
  scenic_driver_nerves_rpi 0.10.1
  scenic_driver_nerves_touch 0.10.0
  shoehorn 0.7.0
  socket 0.3.13
  ssl_verify_fun 1.1.6
  system_registry 0.8.2
  tesla 1.4.0
  timex 3.7.5
  toolshed 0.2.19
  tortoise 0.9.8
  tzdata 1.1.0
  uboot_env 0.3.0
  unicode_util_compat 0.7.0
  yamerl 0.8.1
  yaml_elixir 2.7.0
Upgraded:
  cowboy 2.8.0 => 2.9.0
  cowlib 2.9.1 => 2.11.0
  mime 1.5.0 => 1.6.0
  plug_cowboy 2.4.1 => 2.5.0
  plug_crypto 1.2.1 => 1.2.2
  telemetry 0.4.2 => 0.4.3
* Updating plug_crypto (Hex package)
* Updating telemetry (Hex package)
* Updating mime (Hex package)
* Updating plug_cowboy (Hex package)
* Updating cowboy (Hex package)
* Updating cowlib (Hex package)

Nerves environment
  MIX_TARGET:   rpi3
  MIX_ENV:      dev

==> nerves
==> robotica_nerves
Resolving Nerves artifacts...
  Cached robotica_rpi3
  Cached nerves_toolchain_armv7_nerves_linux_gnueabihf

But I have to know that the package is out of date before I do this. Is there anyway of knowing when such a package is out of date? mix hex.outdated doesn’t seem to help in this case.

I still need to override the ranch version, but at least it seems to work now.

Perhaps worth noting that dependabot from github won’t attempt to upgrade such dependencies either.

What does MIX_TARGET=rpi3 mix hex.outdated —all display?

I think what is happening is that because plug_cowboy is not a direct dependency it is not shown by default.

2 Likes

I didn’t know about the -all option, thanks for that.

1 Like