elixircowboy

Error coming while upgrading cowboy to cowboy2


I have elixir application which I am using with plug(no Phoenix), I was trying to upgrade it to cowboy2 from cowboy. I am using VS code for development, I keep getting following error when I am running server

    ** (Mix) Could not start application ok_api: exited in: 
OkApi.start(:normal, [])
    ** (EXIT) an exception was raised:
    ** (FunctionClauseError) no function clause matching in :proplists.get_value/3
        (stdlib) proplists.erl:215: :proplists.get_value(:num_acceptors, %{max_connections: 16384, num_acceptors: 100, socket_opts: [port: 4001]}, 10)
        (ranch) /Users/ok/Documents/migration/ok_api/deps/ranch/src/ranch.erl:116: :ranch.child_spec/5
        (plug_cowboy) lib/plug/cowboy.ex:183: Plug.Cowboy.child_spec/1
        (ok_api) lib/ok_api.ex:92: OkApi.start/2
        (kernel) application_master.erl:277: :application_master.start_it_old/4

this is my children config

children = [
 Plug.Cowboy.child_spec(scheme: :http, plug: OkApi.Router, options: [port: 4001])
 ]

these 2 version I have in my mix.lock file

"plug": {:hex, :plug, "1.7.1", "8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd", [:mix], [{:mime, "~> 1.0", [hex: :mime, optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, optional: false]}]},
"plug_cowboy": {:hex, :plug_cowboy, "2.0.1", "d798f8ee5acc86b7d42dbe4450b8b0dadf665ce588236eb0a751a132417a980e", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, optional: false]}, {:plug, "~> 1.7", [hex: :plug, optional: false]}]},

app is getting compiled fine but while running only this error is coming. please help.


Solution

  • When updating Cowboy to version 2, make sure you have explicitly updated both ranch and ranch_proxy_protocol to modern versions. Usually putting the line

    {:ranch, "~> 1.7"}
    

    into deps section of your mix.exs file would resolve an issue.