Phoenix error: Response cookies must be set using cowboy_req:set_resp_cookie/3

Hello Elixir forum! :smiley:

I was creating a new Phoenix project via mix, mix ecto.create, mix phx.server and when I visited the root page /, I got this error:

unhandled exit at GET /

{:response_error, :invalid_header, :"Response cookies must be set using cowboy_req:set_resp_cookie/3,4."}

and the code widget below it showing cowboy Erlang code snippet.

Couldn’t find anything related to this online, so I’m trying my luck here.

Phoenix installer v1.7.10

Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Elixir 1.16.0 (compiled with Erlang/OTP 26)

Running on Nobara Linux (Fedora based) x86_64

I was able to reproduce this twice, steps I did:

  1. mix
  2. cd myapp
  3. edit my config/dev.exs file for my local Postgres username/password
  4. mix ecto.create
  5. mix phx.server
  6. access localhost:4000 in Firefox

does anyone have had similar issue before? I used Phoenix with the same version (1.7.10) before in my WSL and macOS and both work fine
any suggestion is very welcomed. thanks in advance!

Hello. I getting this same error. I upgraded to 1.7.10 last week. Today and tried to test something in a new app and :kaboom. this error. Here is what the logs is saying:

[info] GET /
[debug] Processing with InterfaceWeb.PageController.home/2
  Parameters: %{}
  Pipelines: [:browser]
[info] Sent 200 in 717ms
[error] #PID<0.478.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.477.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /
** (exit) {:response_error, :invalid_header, :"Response cookies must be set using cowboy_req:set_resp_cookie/3,4."}

NO WORRIES GUYS. I cannot explain why the issue happen but I can tell how to get rid of it.
You see with phoenix.1.7.10 it seems you need to have :plug_cowboy application version ~> 2.6. So:

In deps function:

defp deps do
      {:phoenix, "~> 1.7.10"},
      {:phoenix_ecto, "~> 4.4"},
      {:ecto_sql, "~> 3.10"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 3.3"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:phoenix_live_view, "~> 0.20.1"},
      {:floki, ">= 0.30.0", only: :test},
      {:phoenix_live_dashboard, "~> 0.8.2"},
      {:esbuild, "~> 0.8", runtime: Mix.env() == :dev},
      {:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
      {:swoosh, "~> 1.3"},
      {:finch, "~> 0.13"},
      {:telemetry_metrics, "~> 0.6"},
      {:telemetry_poller, "~> 1.0"},
      {:gettext, "~> 0.20"},
      {:jason, "~> 1.2"},
      {:dns_cluster, "~> 0.1.1"},
      {:plug_cowboy, "~> 2.5"}    --  remove this line
    {:plug_cowboy, "~> 2.6"}    ++ add this line

Problem solved.
It is really interesting that even if you are newbie you can read the logs and get a sense of what is wrong. I like that.


Nice, this is all happening in real time: Response cookies must be set using cowboy_req · Issue #5705 · phoenixframework/phoenix · GitHub


Thanks so much @kigila for the suggestion and @smathy for the link!
Followed the suggestion(s), upgraded plug_cowboy and it works fine :smiley:


We had the same error and upgrading plug_cowboy helped us as well. I still found it strange as we didn’t upgraded any deps and the running machine had cached deps. If someone can enlighten me what exactly happened here, I would appriciate it. :slight_smile:

Edit: Ah okay, Jose and Chris discussed this on github :slight_smile:
So for everyone dense as me: Cowboy got a new release (2.11), which did not work properly with the plug_cowboy lib (2.6). So you either force upgrade your plug_cowboy or pin your cowboy to 2.10.0, as described by jose in this github thread

{:plug_cowboy, "~> 2.7"} or add {:cowboy, "~> 2.10.0"}

In our team we had to upgrade to 2.7, not 2.6 - is it different with you?

Edit 2:
@ kigila
Nevermind, by explicitly setting the plug_cowboy with ~> the version logic will retrieve 2.7 as well.


Just FYI, the way you’re trying to address the user with @ will not get them notified.

1 Like